![](/img/trans.png)
[英]android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
[英]android.view.inflateexception binary xml file line #1 error inflating class android.widget.relativeLayout
我是android新手。
我刚刚用一个文本栏和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.access$1500(ActivityThread.java:117)
12-24 18:58:31.451: E/AndroidRuntime(1192): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
这是布局的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>
你必须改变
android:background="@layout/activity_main"
至
android:background="@drawable/yourImageName"
有时,当您使用实际上太大而导致内存错误并导致应用程序崩溃的大图像时,也会弹出此错误。 如果您正在使用背景图像或任何大型资产,请确保它们存在并且它们不是太大,然后您将在雨中唱歌!
这一行表示布局的第一行:
android.view.InflateException: Binary XML file line #1: Error inflating class
在第一行有相对布局声明:
所以错误是在android:background
,这不是设置布局背景的正确方法:
android:background="@layout/activity_main"
它应该是一种颜色或可绘制的图像
android:background="@color/backgroundColor"
或android:background="#012345"
要么
android:background="@drawable/backgroundimg"
这是错误的android:background="@layout/activity_main"
应该是
android:background="@color/backgroundColor"
要么
android:background="@drawable/backgroundimg"
在我的情况下修复它的是改变color.xml
的位置
当我从我的其他项目中复制它并将其粘贴到新项目中时,Android Studio将其放在v21
文件夹中,这意味着我的模拟器(v19)无法访问资源文件color.xml
。
我做了以下修复:
color.xml
。 Refactor
>“ Move
。 -v21
。 现在,我的“旧”模拟器能够读取该文件。
我希望它有帮助..
我遇到了同样的问题 - 但是在一个没有背景图像的活动中。
我发现GUI编辑器(当使用Eclipse时 - 我不知道Android Studio)有时会毫无理由地添加buggy属性:
android:background="@layout/activity_main"
我不确定编辑器为什么会这样做 - 也许这是一个错误或只是一个使用错误。
但是,如果活动没有背景图像,则只需删除整个属性!
如果您使用Google Play服务并显示地图,则应在AndroidManifest.xml中添加Meta标记
**<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.