An exception occurs when using fragment in Android, Error inflating class fragment

Exception:
When the fragment is statically referenced in the xml file, the following exception occurs:

Caused by: android.view.InflateException: Binary XML file line #9 in com.hsf.fragmenttest:layout/activity_main: Binary XML file line #9 in com.hsf.fragmenttest:layout/activity_main: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #9 in com.hsf.fragmenttest:layout/activity_main: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #9: Must specify unique android:id, android:tag, or have a parent with an id for com.hsf.fragmenttest.LeftFragment
Insert image description here

Solution:
Add id attribute to fragment in xml
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40261082/article/details/128282987