Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 748
Aviral Avatar asked May 27 '12 12:05

Aviral


2 Answers

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

like image 78
Tri Bui Avatar answered Oct 16 '22 08:10

Tri Bui


  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

like image 39
android developer Avatar answered Oct 16 '22 07:10

android developer