java android.view.InflateException:二进制 XML 文件行 #:错误膨胀类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38146238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android.view.InflateException: Binary XML file line #: Error inflating class
提问by Shubh
This is my xml file
这是我的 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>
and i am getting this in my android monitor
我在我的安卓显示器上看到了这个
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>
I am a beginner in android and i had read answers of various related questions but still i am not getting it where i am wrong.
我是 android 的初学者,我已经阅读了各种相关问题的答案,但我仍然没有在我错的地方得到它。
Edit 1 - Removed unusual code.
编辑 1 - 删除了异常代码。
回答by Harshad Pansuriya
I think the Problem is in your Drawable
Image. The error InflateException is common issue is an out of memory exception when trying to inflate an imageview loading a drawable resource. If one of this resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.
我认为问题出在你的Drawable
形象上。错误 InflateException 是一个常见问题,是在尝试膨胀加载可绘制资源的图像视图时出现内存不足异常。如果此资源之一具有高像素分辨率,则将占用大量内存,从而导致膨胀异常。
So basically verify that the pixel resolution in your drawables images are just the minimum necessary for your layout.
所以基本上验证你的可绘制图像中的像素分辨率只是你的布局所需的最低限度。
回答by Zapnologica
I had this error message, When I was using a library called com.mikhaellopez:circularimageview
and i had the image scale type set to Center_Inside
我收到此错误消息,当我使用一个名为的库com.mikhaellopez:circularimageview
并且我将图像比例类型设置为Center_Inside
which was not supported by the library. After removing that line in the xml layout it worked fine.
图书馆不支持。在 xml 布局中删除该行后,它工作正常。
回答by LaurentY
@drawable/filebinder
or @drawable/diarybookmark
not a valid drawable.
@drawable/filebinder
或@drawable/diarybookmark
不是有效的可绘制对象。
Official doc: https://developer.android.com/guide/topics/resources/drawable-resource.html
官方文档:https: //developer.android.com/guide/topics/resources/drawable-resource.html
Drawable could be png, jpg, gif files or drawable defined by a XML file as state drawable, shape drawable, ...
Drawable 可以是 png、jpg、gif 文件或由 XML 文件定义为状态可绘制、形状可绘制、...
回答by Vasily Kabunov
In my case the reason of this error was that I added the dimen
resource to values-land/dimens.xml
, but not in values/dimens.xml
. Then IDE didn't show any warning/error but at runtime obviously the layout couldn't be drawn.
在我的情况下,这个错误的原因是,我添加了dimen
资源values-land/dimens.xml
,但不是在values/dimens.xml
。然后 IDE 没有显示任何警告/错误,但在运行时显然无法绘制布局。
In general the best way is commenting/deletion views in the layout file one by one to realise which view causes an error.
一般来说,最好的方法是在布局文件中逐个注释/删除视图,以了解哪个视图会导致错误。