android.view.InflateException:二进制XML文件:夸大类片段的错误

我有一个非常令人沮丧的错误,无法解释。我创建了一个Android应用程序,用于Android AppCompat使其与旧版本兼容。这是我的主要活动布局文件:


<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/drawer_layout"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">


    <!-- As the main content view, the view below consumes the entire

         space available using match_parent in both dimensions. -->

    <FrameLayout

        android:id="@+id/container"

        android:layout_width="match_parent"

        android:layout_height="match_parent" />


    <!-- android:layout_gravity="start" tells DrawerLayout to treat

         this as a sliding drawer on the left side for left-to-right

         languages and on the right side for right-to-left languages.

         If you're not building against API 17 or higher, use

         android:layout_gravity="left" instead. -->


    <!-- The drawer is given a fixed width in dp and extends the full height of

         the container. -->

    <fragment android:id="@+id/navigation_drawer"

        android:layout_width="@dimen/navigation_drawer_width"

        android:layout_height="match_parent"

        android:layout_gravity="start"

        android:name="com.fragment.NavigationDrawerFragment" />


</android.support.v4.widget.DrawerLayout>

这是我的活动的主要代码:


public class MainActivity extends ActionBarActivity {

@Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

   }

}

这里的主要问题是:上面的代码在几乎所有设备(受激设备或某些实际设备)上都能流畅运行。但是当我在三星S3上运行它时。它注意到此错误:


java.lang.RuntimeException: Unable to start activity ComponentInfo{view.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class fragment

           

请告诉我如何解决错误,谢谢:)


桃花长相依
浏览 603回答 3
3回答

繁花不似锦

经过长时间的调试,我已解决此问题。(尽管我仍然无法解释原因)。我将财产更改android:name为class。(尽管在Android Document上,他们说这些属性是相同的,但是可以正常使用!!!)因此,它应从:&nbsp;android:name="com.fragment.NavigationDrawerFragment"至class = "com.fragment.NavigationDrawerFragment"因此,新布局应为:<!-- As the main content view, the view below consumes the entire&nbsp; &nbsp; &nbsp;space available using match_parent in both dimensions. --><FrameLayout&nbsp; &nbsp; android:id="@+id/container"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="match_parent" /><!-- android:layout_gravity="start" tells DrawerLayout to treat&nbsp; &nbsp; &nbsp;this as a sliding drawer on the left side for left-to-right&nbsp; &nbsp; &nbsp;languages and on the right side for right-to-left languages.&nbsp; &nbsp; &nbsp;If you're not building against API 17 or higher, use&nbsp; &nbsp; &nbsp;android:layout_gravity="left" instead. --><!-- The drawer is given a fixed width in dp and extends the full height of&nbsp; &nbsp; &nbsp;the container. --><fragment android:id="@+id/navigation_drawer"&nbsp; &nbsp; android:layout_width="@dimen/navigation_drawer_width"&nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; android:layout_gravity="start"&nbsp; &nbsp; class = "com.fragment.NavigationDrawerFragment" />希望这个帮助:)

largeQ

我无法使用提供的答案解决问题。最后我改变了这个:<fragmentandroid:id="@+id/fragment_food_image_gallery"android:name="ir.smartrestaurant.ui.fragment.ImageGalleryFragment"android:layout_width="match_parent"android:layout_height="200dp"android:layout="@layout/fragment_image_gallery"tools:layout="@layout/fragment_image_gallery" />对此:<FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="200dp" />,private void showGallery() {&nbsp; &nbsp; ImageGalleryFragment fragment = new ImageGalleryFragment()&nbsp; &nbsp; getSupportFragmentManager().beginTransaction()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .replace(R.id.fragment_container, fragment)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .commit();&nbsp; &nbsp; }而且有效。如果在片段中使用它,请使用getChildFragmentManager而不是getSupportFragmentManager。

慕容3067478

我遇到了同样的问题,问题,尝试了该线程中的所有答案,但无济于事。我的解决方案是,我没有在Activity XML中添加ID。我认为这并不重要,但确实如此。因此,在活动XML中,我有:<fragment&nbsp; &nbsp; android:name="com.covle.hellocarson.SomeFragment"&nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; android:layout_height="wrap_content"/>但是应该有:<fragment&nbsp; &nbsp; android:id="@+id/some_fragment"&nbsp; &nbsp; android:name="com.covle.hellocarson.SomeFragment"&nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; android:layout_height="wrap_content"/>如果有人乐于对这是为什么发表评论,我想向其他人说,我希望这会有所帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android