Binary XML file line #7: Error inflating class fragment,

Source: Internet
Author: User

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 ???

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.