android.view.InflateException:二进制 XML 文件行 #:膨胀错误 class

android.view.InflateException: Binary XML file line #: Error inflating class

这是我的 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:background="@drawable/filebinder" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="14"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="6"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="30 July"
                    android:textColor="#03a9f4"
                    android:textSize="32sp" />

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

并且我在我的 android 监视器中得到了这个

07-01 18:32:04.693 10005-10005/com.mindefy.kidster E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
07-01 18:32:12.293 10005-10005/com.mindefy.kidster E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mindefy.kidster/com.mindefy.kidster.DiaryEntry.diaryEntryTeacherActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>

我是 android 的初学者,我已经阅读了各种相关问题的答案,但我仍然不明白我错在哪里。

编辑 1 - 删除了异常代码。

@drawable/filebinder@drawable/diarybookmark 不是有效的可绘制对象。

官方文档:https://developer.android.com/guide/topics/resources/drawable-resource.html

可绘制对象可以是 png、jpg、gif 文件或由 XML 文件定义为状态可绘制对象、形状可绘制对象...

我认为问题出在您的 Drawable 图片中。错误 InflateException 是一个常见问题,是在尝试膨胀加载可绘制资源的图像视图时出现内存不足异常。如果其中一个资源具有高像素分辨率,则会占用大量内存,从而导致膨胀异常。

因此基本上验证可绘制图像中的像素分辨率是否只是布局所需的最低像素分辨率。

我收到此错误消息,当我使用名为 com.mikhaellopez:circularimageview 的库并将图像比例类型设置为 Center_Inside

图书馆不支持。在 xml 布局中删除该行后,它工作正常。

在我的例子中,这个错误的原因是我将 dimen 资源添加到 values-land/dimens.xml,而不是 values/dimens.xml。然后 IDE 没有显示任何 warning/error 但是在运行时显然无法绘制布局。

一般来说最好的方法是commenting/deletion布局文件中的视图一个一个地了解是哪个视图导致了错误。