Aviral
Aviral

Reputation: 1141

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

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.

Upvotes: 9

Views: 25476

Answers (4)

Mridul Shrivastava
Mridul Shrivastava

Reputation: 109

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

<item name="windowActionBar">false</item> 

Upvotes: 0

Lee Yi Hong
Lee Yi Hong

Reputation: 1340

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.

Upvotes: 0

android developer
android developer

Reputation: 116342

  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

Upvotes: 3

Tri Bui
Tri Bui

Reputation: 1456

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".

Upvotes: 6

Related Questions