【问题标题】:android.view.InflateException: Binary XML file line #: Error inflating classandroid.view.InflateException: Binary XML file line #: Error inflating class
【发布时间】:2016-11-03 21:57:02
【问题描述】:

这是我的 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>

我在我的安卓显示器中得到了这个

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 - 删除异常代码。

【问题讨论】:

  • 您是否在清单文件中定义了您的活动?
  • 是的,我已经在清单中定义了它

标签: java android xml inflate-exception


【解决方案1】:

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

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

【讨论】:

  • 感谢@Ironman 我已将我的图像放入可绘制的 v-21 中。我知道这很愚蠢,但还是谢谢
  • 我曾经在使用 Android Studion 选择导航模板时遇到过这个问题。我所做的只是利用 drawable 而忽略了我认为导致主要问题的 drawable v-21这里
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

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

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

    Drawable 可以是 png、jpg、gif 文件或由 XML 文件定义为 state drawable、shape drawable 的 drawable...

    【讨论】:

      【解决方案4】:

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

      一般来说最好的方法是在布局文件中逐个注释/删除视图,以了解哪个视图导致错误。

      【讨论】:

        猜你喜欢
        • 2020-06-27
        • 1970-01-01
        • 2015-08-21
        • 2012-02-09
        • 2012-03-04
        • 2013-06-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多