无法启动活动ComponentInfo android.view.InflateException:二进制XML文件行#19:错误膨胀类片段

时间:2016-08-22 09:50:05

标签: android android-studio

我有一个有firebase的应用程序。 所以我得到崩溃报告 但我不知道为什么会发生以及如何解决。

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.homers.health_coach/com.homers.health_coach.MainActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2540)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2599)
android.app.ActivityThread.access$900 (ActivityThread.java:174)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:146)
android.app.ActivityThread.main (ActivityThread.java:5748)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1291)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1107)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down


Caused by android.view.InflateException: Binary XML file line #19: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:719)
android.view.LayoutInflater.rInflate (LayoutInflater.java:761)
android.view.LayoutInflater.rInflate (LayoutInflater.java:769)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:855)
android.view.LayoutInflater.rInflate (LayoutInflater.java:751)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:855)
android.view.LayoutInflater.rInflate (LayoutInflater.java:751)
android.view.LayoutInflater.inflate (LayoutInflater.java:498)
android.view.LayoutInflater.inflate (LayoutInflater.java:398)
android.view.LayoutInflater.inflate (LayoutInflater.java:354)
android.support.v7.app.AppCompatDelegateImplV7.setContentView (AppCompatDelegateImplV7.java:256)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:109)
com.homers.health_coach.MainActivity.onCreate (MainActivity.java:58)
android.app.Activity.performCreate (Activity.java:5600)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1093)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2504)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2599)
android.app.ActivityThread.access$900 (ActivityThread.java:174)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:146)
android.app.ActivityThread.main (ActivityThread.java:5748)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1291)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1107)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down


Caused by java.lang.IllegalStateException: Fragment com.homers.health_coach.fragment_workout_list did not create a view.
android.support.v4.app.FragmentManagerImpl.onCreateView (FragmentManager.java:2314)
android.support.v4.app.FragmentController.onCreateView (FragmentController.java:111)
android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView (FragmentActivity.java:314)
android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView (BaseFragmentActivityHoneycomb.java:31)
android.support.v4.app.FragmentActivity.onCreateView (FragmentActivity.java:79)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:695)
android.view.LayoutInflater.rInflate (LayoutInflater.java:761)
android.view.LayoutInflater.rInflate (LayoutInflater.java:769)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:855)
android.view.LayoutInflater.rInflate (LayoutInflater.java:751)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:855)
android.view.LayoutInflater.rInflate (LayoutInflater.java:751)
android.view.LayoutInflater.inflate (LayoutInflater.java:498)
android.view.LayoutInflater.inflate (LayoutInflater.java:398)
android.view.LayoutInflater.inflate (LayoutInflater.java:354)
android.support.v7.app.AppCompatDelegateImplV7.setContentView (AppCompatDelegateImplV7.java:256)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:109)
com.homers.health_coach.MainActivity.onCreate (MainActivity.java:58)
android.app.Activity.performCreate (Activity.java:5600)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1093)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2504)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2599)
android.app.ActivityThread.access$900 (ActivityThread.java:174)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1321)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:146)
android.app.ActivityThread.main (ActivityThread.java:5748)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1291)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1107)
dalvik.system.NativeStart.main (NativeStart.java)

这里是布局xml代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.homers.health_coach.MainActivity"
    tools:showIn="@layout/app_bar_main">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <fragment
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.homers.health_coach.fragment_community"
            android:id="@+id/fragment_community" />

        <fragment
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.homers.health_coach.fragment_workout_list"
            android:id="@+id/fragment_workout_list" />
    </FrameLayout>
</LinearLayout>

58line是

setContentView(R.layout.activity_main);

请告诉我为什么会发生以及如何解决它.. 请帮帮我。 感谢:)

3 个答案:

答案 0 :(得分:0)

<{1}} onCreateView()因某种原因返回fragment_workout_list

答案 1 :(得分:0)

错误非常明显,您可能未在onCreateView的{​​{1}}方法中返回视图:

  

由java.lang.IllegalStateException引起:片段com.homers.health_coach.fragment_workout_list没有创建视图。

确保在fragment_workout_list

中有类似的内容
fragment_workout_list

答案 2 :(得分:0)

您尚未在线性布局中指定方向,我认为在您的情况下应该是垂直的。据我所见,错误清楚地表明xml文件有问题,因此无法充气