Gridview v7 support for older api android.support.v7.widget.Gridlayout failed to instaniate

12,502

I encountered the same problem and I fixed it by importing ".../android-sdks/extras/android/support/v7/gridlayout" as "Existing Android Code Into WorkSpace".

Its project name is "android.support.v7.widget.GridLayout" which is a library. Then you should "Add..." it as a library in the Project/Properties/Android/Library panel. Then it should work. Hope this would be helpful for you.

Below is my xml:

<ScrollView
    xmlns:grid="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp" >

    <android.support.v7.widget.GridLayout
        android:id="@+id/gridlayout_home"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:paddingBottom="5dp"
        grid:columnCount="4"
        grid:rowCount="4" >
    </android.support.v7.widget.GridLayout>
</ScrollView>
Share:
12,502
Craig Smith
Author by

Craig Smith

Recently I completed an associates degree in applied computer science at Mohave Community College. Since then I moved to Poland with my wife and 2 kids where I hope to further my education and find a job programming. I have some knowledge in C#, Java, and VB.

Updated on June 14, 2022

Comments

  • Craig Smith
    Craig Smith about 2 years

    I've been trying to use the v7 support library to use a grid layout in my android project. I've seen that many people have had the same issues that I'm having but all of their fixes don't work for me. I've updated java. I've updated the latest support library. I've added the support package to the build path. I've tried dragging a gridview onto a view and allow eclipse import the package. Non of these work. I continue to get android.support.v7.widget.GridLayout failed to instantiate. I even created a test project and started with the support grid layout and the same error. Anyone have any other ideas? These are some places I've looked for help:

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

    IntelliJ and android.support.v7.widget.GridLayout

    Eclipse and Android SL GridLayout not working together - "android.support.v7.widget.GridLayout could not be instantiated"

    among many others....

    Here's my activity_main.xml:

     <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.GridLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:alignmentMode="alignBounds"
        app:columnCount="6"
        app:columnOrderPreserved="false"
        app:useDefaultMargins="true" >
    
        <EditText
            android:id="@+id/total"
            app:layout_column="0"
            app:layout_columnSpan="6"
            app:layout_gravity="left"
            app:layout_row="0"
            android:clickable="false"
            android:ems="10"
            android:inputType="none|number"
            android:textAlignment="textEnd"
            android:width="500dp" >
    
            <requestFocus />
        </EditText>
    
        <Button
            android:id="@+id/Button8"
            app:layout_column="1"
            app:layout_row="1"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="8" />
    
        <Button
            android:id="@+id/Button9"
            app:layout_column="2"
            app:layout_row="1"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="9" />
    
        <Button
            android:id="@+id/Button4"
            app:layout_column="0"
            app:layout_row="2"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="4" />
    
        <Button
            android:id="@+id/Button5"
            app:layout_column="1"
            app:layout_row="2"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="5" />
    
        <Button
            android:id="@+id/Button6"
            app:layout_column="2"
            app:layout_row="2"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="6" />
    
        <Button
            android:id="@+id/ButtonMultiply"
            app:layout_column="3"
            app:layout_row="2"
            android:background="@drawable/custom_button"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="Multiply"
            android:text="*"
            android:textColor="@color/light_grey" />
    
        <Button
            android:id="@+id/Button1"
            app:layout_column="0"
            app:layout_row="3"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="1" />
    
        <Button
            android:id="@+id/Button2"
            app:layout_column="1"
            app:layout_row="3"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="2" />
    
        <Button
            android:id="@+id/Button3"
            app:layout_column="2"
            app:layout_row="3"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="3" />
    
        <Button
            android:id="@+id/ButtonMinus"
            app:layout_column="3"
            app:layout_row="3"
    
            android:background="@drawable/custom_button"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="Subtract"
            android:text="-"
            android:textColor="@color/light_grey" />
    
        <Button
            android:id="@+id/ButtonDivide"
            app:layout_column="3"
            app:layout_gravity="right"
            app:layout_row="1"
            app:layout_rowSpan="2"
            android:background="@drawable/custom_button"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="Divide"
            android:text="/"
            android:textColor="@color/light_grey" />
    
        <Button
            android:id="@+id/button0"
            app:layout_column="0"
            app:layout_columnSpan="2"
            app:layout_row="4"
            android:background="@drawable/button_light_grey"
            android:minHeight="20dp"
            android:minWidth="82dp"
            android:onClick="numberButtonEventHandler"
            android:text="0" />
    
        <Button
            android:id="@+id/buttonPoint"
            app:layout_column="2"
            app:layout_row="4"
            android:background="@drawable/button_light_grey"
            android:minHeight="20dip"
            android:minWidth="40dp"
            android:onClick="numberButtonEventHandler"
            android:text="."
            android:width="20dip" />
    
        <Button
            android:id="@+id/ButtonPlus"
            app:layout_column="3"
            app:layout_row="4"
            android:background="@drawable/custom_button"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="Add"
            android:text="+"
            android:textColor="@color/light_grey" />
    
        <Button
            android:id="@+id/ButtonEqueals"
            app:layout_column="4"
            app:layout_row="3"
            app:layout_rowSpan="2"
            android:background="@drawable/custom_button"
            android:height="40dp"
            android:minHeight="82dp"
            android:minWidth="20dp"
            android:onClick="Equeals"
            android:text="="
            android:textColor="@color/light_grey"
            android:width="40dp" />
    
        <Button
            android:id="@+id/Button7"
            app:layout_column="0"
            app:layout_row="1"
            android:background="@drawable/button_light_grey"
            android:minHeight="40dip"
            android:minWidth="40dip"
            android:onClick="numberButtonEventHandler"
            android:text="7" />
    
    
    
    </android.support.v7.widget.GridLayout>
    

    this is a snip of the project tree showing referenced libraries, dependencies, and libs all pointing to v7 gridlayout: New Edit, asked to remove one reference.

    enter image description here

    This is the exact exception I get:

    java.lang.ClassNotFoundException: android.support.v7.gridlayout.R$dimen
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        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(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
        at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
        at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
        at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:385)
        at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
        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:440)
        at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1545)
        at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1302)
        at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1059)
        at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:686)
        at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
        at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:292)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
        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:3028)
        at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1749)
        at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:278)
        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:4169)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
        at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
        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:353)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    
    • Craig Smith
      Craig Smith about 11 years
      nobody has any ideas?
    • Raghav Sood
      Raghav Sood about 11 years
      You seem to have the v7 library imported from two different locations. Try removing the one in referenced libraries.
    • Craig Smith
      Craig Smith about 11 years
      @RaghavSood I removed one of the references from the build path as you asked, but I still get the same error. I have now posted the exact error I receive from eclipse.
  • Craig Smith
    Craig Smith about 11 years
    If it's in the generated folder, shouldn't it generate by it's self? I can't copy the v7 grid layout there because when I clean the project it gets deleted.
  • Rohit
    Rohit about 11 years
    no if you give path it in configure build path then after cleaning it will not removed
  • Craig Smith
    Craig Smith about 11 years
    after looking at my code in Linux I see that in fact there is the support.v7.gridview in the generated code. In windows this still doesn't work but I think it's a problem with eclipse.
  • mr5
    mr5 about 10 years
    I'm missing the .widget part here, means I imported the wrong project?
  • Leo supports Monica Cellio
    Leo supports Monica Cellio over 9 years
    This is not a solution. GridLayout and GridView are different components used for totally different things.
  • Leo supports Monica Cellio
    Leo supports Monica Cellio over 9 years
    This is not a solution. GridLayout and GridView are different components used for totally different things.
  • Leo supports Monica Cellio
    Leo supports Monica Cellio over 9 years
    This is not a solution. GridLayout and GridView are different components used for totally different things.