无法启动 activity ComponentInfo:android.view.InflateException:二进制 XML 文件行 #63:膨胀 class <unknown> 时出错

Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #63: Error inflating class <unknown>

无法启动 activity ComponentInfo:android.view.InflateException:二进制 XML 文件行 #63:膨胀 class <未知>

时出错

让我们从问题开始:
该应用程序 android 8.0 one my oneplus
上运行良好
,但 不运行 我的 android 5.0 J5 (2015)
我首先在 activity_main.xml 中的 #0 行出现错误,但是在 gradle.properties 中添加 android.enableAapt2=false 之后] 文件我在行 #63
上遇到错误所以我认为它有帮助。

MainActivity.class 中的 40 行也是 setContentView(R.layout.activity_main);.
你可以在我的github here.

上查看整个项目的源码

堆栈跟踪

Process: me.toxicmushroom.broodtimer, PID: 5160
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.toxicmushroom.broodtimer/me.toxicmushroom.broodtimer.MainActivity}: android.view.InflateException: Binary XML file line #63: Error inflating class <unknown>
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
              at android.app.ActivityThread.access0(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
              Caused by: android.view.InflateException: Binary XML file line #63: Error inflating class <unknown>
      at android.view.LayoutInflater.createView(LayoutInflater.java:633)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
              at me.toxicmushroom.broodtimer.MainActivity.onCreate(MainActivity.java:40)
              at android.app.Activity.performCreate(Activity.java:5990)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
              at android.app.ActivityThread.access0(ActivityThread.java:151) 
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
              at android.os.Handler.dispatchMessage(Handler.java:102) 
              at android.os.Looper.loop(Looper.java:135) 
              at android.app.ActivityThread.main(ActivityThread.java:5254) 
              at java.lang.reflect.Method.invoke(Native Method) 
              at java.lang.reflect.Method.invoke(Method.java:372) 
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
              Caused by: java.lang.reflect.InvocationTargetException
              at java.lang.reflect.Constructor.newInstance(Native Method)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
              at android.view.LayoutInflater.createView(LayoutInflater.java:607)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
              at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
              at me.toxicmushroom.broodtimer.MainActivity.onCreate(MainActivity.java:40) 
              at android.app.Activity.performCreate(Activity.java:5990) 
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
              at android.app.ActivityThread.access0(ActivityThread.java:151) 
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
              at android.os.Handler.dispatchMessage(Handler.java:102) 
              at android.os.Looper.loop(Looper.java:135) 
              at android.app.ActivityThread.main(ActivityThread.java:5254) 
              at java.lang.reflect.Method.invoke(Native Method) 
              at java.lang.reflect.Method.invoke(Method.java:372) 
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
              Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02005e
              at android.content.res.Resources.getValue(Resources.java:1266)
              at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:328)
              at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
              at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
              at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
              at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
              at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:175)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:151)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at me.toxicmushroom.broodtimer.MainActivity.onCreate(MainActivity.java:40) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access0(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="me.toxicmushroom.broodtimer.MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="16dp"
        app:popupTheme="@style/Theme.AppCompat.Light" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@id/toolbar"
        android:text="Loaded Broden"
        android:textAlignment="center"
        android:textColor="@android:color/white"
        android:textSize="20dp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_alignLeft="@+id/fab"
        android:layout_alignStart="@+id/fab"
        android:layout_alignTop="@+id/fab"
        app:backgroundTint="@android:color/holo_blue_dark"
        app:srcCompat="@drawable/ic_create_new_folder_white_24dp"
        tools:ignore="VectorDrawableCompat" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab1"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_alignLeft="@+id/fab"
        android:layout_alignStart="@+id/fab"
        android:layout_alignTop="@+id/fab"
        app:backgroundTint="@android:color/holo_blue_dark"
        app:srcCompat="@drawable/ic_folder_open_white_24dp"
        tools:ignore="VectorDrawableCompat" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_margin="21dp"
        app:backgroundTint="@color/colorPrimary"
        app:srcCompat="@drawable/ic_add_white_24dp"
        tools:ignore="VectorDrawableCompat" />
</RelativeLayout>

堆栈跟踪的关键部分:

Caused by: android.view.InflateException: Binary XML file line #63: Error inflating class <unknown>

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02005e

第 63 行指向布局中的最后一个 FloatingActionButton。查找您的 github 项目,ic_add_white_24dp 仅在 drawable-v24 中,但不在不合格的 drawable 文件夹中。因此代码不适用于 API 级别低于 24.