【问题标题】:Android:Inflate Exception in the class fragmentAndroid:类片段中的Inflate Exception
【发布时间】:2023-03-30 21:27:01
【问题描述】:

我试图在我的代码中使用片段。在我单击片段并尝试调整屏幕方向后,我收到如下错误,...

Unable to start activity ComponentInfo{com.example.frag/com.example.frag.Activity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment

我的 Xml

<LinearLayout android:id="@+id/linear" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" >
<ListView android:id="@+id/android:list" android:layout_height="wrap_content" android:layout_width="fill_parent"/> 
<fragment android:id="@+id/frag" android:layout_height="fill_parent" android:layout_width="fill_parent" class="com.example.frag.MyFragment"/> 

【问题讨论】:

    标签: android android-fragments


    【解决方案1】:

    我找到了答案。, 我忘了扩展 FragmentActivity 而不是 Activity..

    它现在可以工作了。

    参考:https://stackoverflow.com/a/9168223/1542636

    【讨论】:

      【解决方案2】:

      根据您提供的有限信息,您似乎遇到了this 帖子中解决的相同问题。

      【讨论】:

        【解决方案3】:

        试试这个:

         <fragment
            android:id="@+id/frag"
            android:name="com.example.frag.MyFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:layout="@layout/frag_layout" />
        

        您必须使用 android:name="fully qualified path"。你用过 class=""。

        【讨论】:

          猜你喜欢
          • 2019-03-26
          • 1970-01-01
          • 2014-10-18
          • 1970-01-01
          • 2014-09-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多