Binary XML file line #7: Error inflating class fragment,
I have been learning fragment for the past few days. I want to write a program on my own and try it. I didn't expect it to be a problem when I first wrote it.
An error occurred while loading the main layout file activity_main.xml.
13:11:12-12. 873: E/AndroidRuntime (2022): java. lang. runtimeException: Unable to start activity ComponentInfo {com. gentleni. demo_grideview_002/com. gentleni. demo_grideview_002.MainActivity}: android. view. inflateException: Binary XML file line #8: Error inflating class fragment
06-12 13:11:12. 873: E/AndroidRuntime (2022): Caused by: android. view. InflateException: Binary XML file line #8: Error inflating class fragment
I checked the relevant information, and it turns out to be a fragment version Compatible problem.
Android. app. Fragment is compatible with android: minSdkVersion = "11", that is, version 3.0.
The Minimum Version compatible with android. support. v4.app. Fragment is android: minSdkVersion = "4", that is, version 1.6.
If the support. v4 package is used, fragment labels cannot be defined in xml. My xml code:
<fragment android:id="@+id/id_MYFragment" android:name="com.gentleni.demo_grideview_002.MyFragment" android:layout_width="wrap_content" android:layout_height="wrap_content" />
The Fragment label is supported only when the new package android. app. fragment is used. This means that the fragment of v4 package cannot be statically loaded ???