Java android.view.inflateexception 二进制 xml 文件第 1 行错误 inflating 类 android.widget.relativeLayout
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20762720/
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 #1 error inflating class android.widget.relativeLayout
提问by jazz b
I am new in android.
I just made a new layout with one text bar and 2 buttons but it didn't work, I am posting the stack trace and my relative layout file any idea about this? I saw the same question there which says to decrease the draw able size. But it didn't help in my case or I didn't now much about how to decrease it.
Here is some of my stack trace:
我是安卓新手。
我刚刚创建了一个带有一个文本栏和 2 个按钮的新布局,但它不起作用,我正在发布堆栈跟踪和我的相关布局文件对此有什么想法吗?我在那里看到了同样的问题,它说要减少可绘制的尺寸。但这对我来说没有帮助,或者我现在不太了解如何减少它。这是我的一些堆栈跟踪:
D/AndroidRuntime(1192): Shutting down VM
W/dalvikvm(1192): threadid=1: thread exiting with uncaught exception (group=0xb60cc4f0)
E/AndroidRuntime(1192): FATAL EXCEPTION: main
E/AndroidRuntime(1192): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellomissworld/com.example.hellomissworld.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
E/AndroidRuntime(1192):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-24 18:58:31.451: E/AndroidRuntime(1192): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-24 18:58:31.451: E/AndroidRuntime(1192): at android.app.ActivityThread.access00(ActivityThread.java:117)
12-24 18:58:31.451: E/AndroidRuntime(1192): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
and that is the xml file of lay out :
这是布局的xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@layout/activity_main"
android:focusable="false"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="24dp"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_alignParentTop="true"
android:text="@string/typehere"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/editText1"
android:text="@string/ok" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_toLeftOf="@+id/button2"
android:text="@string/cancel" />
</RelativeLayout>
采纳答案by Piyush
You have to change
你必须改变
android:background="@layout/activity_main"
to
到
android:background="@drawable/yourImageName"
回答by RajaReddy PolamReddy
This is wrong android:background="@layout/activity_main"
should be
这是错误的android:background="@layout/activity_main"
应该是
android:background="@color/backgroundColor"
or
或者
android:background="@drawable/backgroundimg"
回答by Hamad
this line is indicating the first line of the layout:
这一行表示布局的第一行:
android.view.InflateException: Binary XML file line #1: Error inflating class
and at the first line there is Relative layout declaration:
第一行是相对布局声明:
So The error is on android:background
, and This is not the correct way to set background of layout:
所以错误是 on android:background
,这不是设置布局背景的正确方法:
android:background="@layout/activity_main"
it should be a color or drawable image
它应该是彩色或可绘制的图像
android:background="@color/backgroundColor"
or android:background="#012345"
android:background="@color/backgroundColor"
或者 android:background="#012345"
or
或者
android:background="@drawable/backgroundimg"
回答by Akshay
If you use Google Play Services and show Maps you should add Meta tag in AndroidManifest.xml
如果您使用 Google Play 服务并显示地图,您应该在 AndroidManifest.xml 中添加 Meta 标签
**<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />**
回答by ColossalChris
Sometimes this error can also pop up when you are using a large image that is actually too big that leads to a memory error and crashes your app. If you are using background images or any large assets make sure they exist and that they aren't too big and then you'll be singing in the rain!
有时,当您使用的大图像实际上太大导致内存错误并导致应用程序崩溃时,也会弹出此错误。如果您使用背景图像或任何大型资产,请确保它们存在并且它们不会太大,然后您就会在雨中唱歌!
回答by Barakuda
What fixed it in my case was to change the location of my color.xml
在我的情况下修复它的是改变我的位置 color.xml
As I copied it from some other project of mine and pasted it in the new project, Android Studio placed it in the v21
folder, meaning my emulator (v19) could not reach the resource file color.xml
.
当我从我的其他项目中复制它并将其粘贴到新项目中时,Android Studio 将其放置在v21
文件夹中,这意味着我的模拟器(v19)无法访问资源文件color.xml
.
I did the following to fix it:
我做了以下修复:
- Right click on
color.xml
. - Select
Refactor
>Move
. - On the dialog that open, removed the suffix
-v21
.
- 右键单击
color.xml
。 - 选择
Refactor
>Move
。 - 在打开的对话框中,删除后缀
-v21
.
Now, my "old" emulator was able to read the file.
现在,我的“旧”模拟器能够读取文件。
I hope it helps..
我希望它有帮助..
回答by Martin Rosenau
I had the same problem - but in a activity that had no background image.
我有同样的问题 - 但在没有背景图像的活动中。
I found out that the GUI editor (when using Eclipse - I don't know about Android Studio) sometimes adds the buggy property without any reason:
我发现 GUI 编辑器(使用 Eclipse 时 - 我不了解 Android Studio)有时会无缘无故地添加错误属性:
android:background="@layout/activity_main"
I'm not sure why the editor does so - maybe it is a bug or simply a usage error.
我不确定编辑器为什么这样做 - 也许这是一个错误或只是一个使用错误。
However if the activity does not have a background image the entire property simply has to be deleted!
但是,如果活动没有背景图像,则只需删除整个属性!