Eclipse giving an error of android.support.v7.widget.GridLayout failed to instantiate
Asked Answered
Q

4

9

I have tried to incorporate the GridLayout from the support library, but it is not working. My target build is for API version 10. The XML code I am using is shown below:

    <?xml version="1.0" encoding="UTF-8"?>
    <android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:grid="http://schemas.android.com/apk/res-auto"      
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android.support.v7.widget.columnCount="6" >
 <Button
     android:id="@+id/button1"
     android.support.v7.widget.layout_column="1" 
     android.support.v7.widget.layout_columnSpan="2"
     android.support.v7.widget.layout_gravity="left"
     android.support.v7.widget.layout_row="1"
     android:text="Button" />

 </android.support.v7.widget.GridLayout>

When Eclipse tries to compile this, the error given is: android.support.v7.widget.GridLayout failed to instantiate. The stack trace is:

    java.lang.NoClassDefFoundError: android/support/v7/gridlayout/R$dimen
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:402)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:166)
at com.android.layoutlib.bridge.android.BridgeInflater.loadCustomView(BridgeInflater.java:205)
at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:133)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1361)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1115)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:941)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:585)
at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:290)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2746)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1433)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

Based on the fact that nobody is facing this problem, I suspect that I have not setup the v7 library correctly. The steps I have followed:

  1. Create a library project at the "gridlayout" directory
  2. Added this project to my Main project
  3. Added the jar from the gridlayout lib directory to the lib directory of my main project

Any help will be much appreciated.

Quinonoid answered 27/5, 2012 at 12:28 Comment(3)
Thanks for your efforts to help guys, but nothing was working. But, finally found the solution. EXTREMELY embarrassed to say that I needed to update the JAVA on my machine. Apologies...Quinonoid
i have exactly the same issue, the closing as does not make sense for me.Thief
:-) Hopefully, the solution to upgrade Java worked for you also...Quinonoid
S
6

Update your Compatibility Library to revision 8, then follow the instruction in README.txt file in "extras\android\compatibility\v7\gridlayout" folder.

Hope this help you.

Notes: You must use grid:columnCount="6" instead of android.support.v7.widget.columnCount="6" because you declare the prefix "grid" in xmlns:grid="http://schemas.android.com/apk/res-auto".

Superstructure answered 27/5, 2012 at 18:34 Comment(2)
+1 for the hidden README! But Eclipse is not able to find the GridLayout class from within my project i.e. I cannot do import android.support.v7.widget.GridLayout because only three widgets are available here - PopupMenu, SearchView, ShareActionProvider. Is there some pre-requisite step required to include the GridLayout class ?Burrus
oops i had not imported this support project into my workspace. Works now.Burrus
F
3
  1. update eclipse, adt (even to version 20 preview 2) , sdk manager and the support library .

  2. try to restart eclipse and see if that helps.

  3. try to create a totally new project (with low sdk being used for the min and target sdk , but not for the one specified on the project.properties file ) and drag the gridLayout in the visual editor. this will automatically add the needed library.

  4. if nothing helps , try this example : http://code.google.com/p/android-playground/source/checkout

Flaw answered 27/5, 2012 at 20:57 Comment(0)
S
0

I try a number of solution provided by different contributor (eg restart Eclipse, removing and adding libary etc)

After looking at this site, I did the following:

  1. Replace all the library android-support-v4.jar with the android-sdk (hoping that it will be the latest copy)
  2. I commented the Gridlayout in xml and use the layout editor just drag gridlayout.

After that everything works for me. I am not sure which step is the one that fix it but there is no harm trying.

Spearhead answered 25/7, 2014 at 9:58 Comment(0)
A
0

It seems you are doing for Android L but anyway include this line inside your styles.xml.

<item name="windowActionBar">false</item> 
Alfano answered 8/9, 2015 at 5:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.