Good day.

Tell me, please, what could be the problem. When developing an application using GridLayout, I connected the android.support.v7 library to the application so that this GridLayout can be supported starting with Android 2.3. But for some reason it is not possible to run the application on the emulator, since I get the following (part of the log):

09-03 09:33:02.058: E/AndroidRuntime(1234): FATAL EXCEPTION: main 09-03 09:33:02.058: E/AndroidRuntime(1234): Process: ru.dontsov.labs, PID: 1234 09-03 09:33:02.058: E/AndroidRuntime(1234): java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.dontsov.labs/ru.dontsov.labs.activities.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v7.widget.GridLayout 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.app.ActivityThread.access$800(ActivityThread.java:135) 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.os.Handler.dispatchMessage(Handler.java:102) 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.os.Looper.loop(Looper.java:136) 09-03 09:33:02.058: E/AndroidRuntime(1234): at android.app.ActivityThread.main(ActivityThread.java:5017) 09-03 09:33:02.058: E/AndroidRuntime(1234): at java.lang.reflect.Method.invokeNative(Native Method) 09-03 09:33:02.058: E/AndroidRuntime(1234): at java.lang.reflect.Method.invoke(Method.java:515) 09-03 09:33:02.058: E/AndroidRuntime(1234): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 09-03 09:33:02.058: E/AndroidRuntime(1234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 09-03 09:33:02.058: E/AndroidRuntime(1234): at dalvik.system.NativeStart.main(Native Method) 

In xml activity_main (part):

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0099cc" tools:context=".MainActivity" > <android.support.v7.widget.GridLayout android:layout_width="wrap_content" android:layout_height="wrap_content" app:columnCount="4" app:orientation="vertical" app:rowCount="7" > <Button android:id="@+id/btnOne" style="?android:attr/buttonStyleSmall" android:layout_width="65dp" android:layout_height="65dp" app:layout_column="0" app:layout_gravity="top|left" app:layout_row="1" android:contentDescription="@string/_1" android:onClick="buttonClick" android:layout_margin="2dp" android:background="@drawable/round_button" android:shadowColor="#A8A8A8" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="5" android:textColor="#000" android:textSize="20sp" android:text="@string/_1" /> <Button android:id="@+id/btnTwo" style="?android:attr/buttonStyleSmall" android:layout_width="65dp" android:layout_height="65dp" app:layout_column="1" app:layout_gravity="top|left" app:layout_row="1" android:contentDescription="@string/_2" android:onClick="buttonClick" android:text="2" android:layout_margin="2dp" android:background="@drawable/round_button" android:shadowColor="#A8A8A8" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="5" android:textColor="#000" android:textSize="20sp" /> </android.support.v7.widget.GridLayout> </RelativeLayout> 

What could be the problem? Thanks a lot in advance!

  • 3
    The library is somehow incorrectly connected, it seems to me. - Vladyslav Matviienko

1 answer 1

The answer is: the solution in the Anglo-Saxon

In Russian:

1) The problem is the absence of the required class in the project libraries.

2) We need to add another library in the same way as support-lib: first add the "project from existing code" to the workspace from here:

your-android-sdk \ extras \ android \ support \ v7 \ gridlayout

then in the properties of your project add the previous project as a library.

3) Everything works.

  • That's the thing, I did it, I added this project as a library, but it still does not work. - Rumato
  • I took the above code, deleted all the attributes with the namespace "app", and it all started. Are you sure you hooked up both libraries? In your question, clearly only one thing is said. - Yuriy SPb
  • one
    Many thanks for the help, yes, the problem was in connecting the libraries. - Rumato