【问题标题】:Binary XML file <line 20>: Error inflating class <Unknown>二进制 XML 文件 <第 20 行>:膨胀类 <Unknown> 时出错
【发布时间】:2014-06-07 09:13:25
【问题描述】:

06-07 15:02:07.048: E/dalvikvm-heap(1657): 9007416 字节的外部分配对于这个进程来说太大了。 06-07 15:02:07.098: E/GraphicsJNI(1657): VM 不允许我们分配 9007416 字节

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|left|right"
android:background="@drawable/bg"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/top_red_bar"
    android:layout_alignParentLeft="true"
    android:paddingLeft="0dp"
    android:scaleType="centerCrop" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignTop="@+id/imageView1"
    android:layout_centerHorizontal="true"
   
    android:src="@drawable/job_bar" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="238dp"
    android:layout_height="50dp"
    android:layout_below="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginTop="123dp"
    android:src="@drawable/button" 
    android:alpha="0.85"
    android:onClick="myhandler"/>

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/imageView3"
    android:layout_marginTop="24dp"
    android:src="@drawable/button" 
    android:alpha="0.85"/>

<ImageView
    android:id="@+id/imageView5"
    android:layout_width="35dp"
    android:layout_height="45dp"
    android:layout_above="@+id/imageView4"
    android:layout_alignLeft="@+id/imageView3"
    android:layout_marginLeft="21dp"
    android:src="@drawable/employer" />

<ImageView
    android:id="@+id/imageView6"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignLeft="@+id/imageView5"
    android:layout_alignTop="@+id/imageView4"
    android:src="@drawable/jobseekers" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView5"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="18dp"
    android:layout_toRightOf="@+id/imageView6"
    android:text="Employer"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#ffffff"
    android:textStyle="bold" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignTop="@+id/imageView4"
    android:text="Job Seekers"
    
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#ffffff"
    android:textStyle="bold" />


</RelativeLayout>

我的应用程序因错误声明 Binary XML file &lt;line 20&gt;: Error inflating class &lt;Unknown&gt; 而崩溃。 为什么会这样??谁能解决这个问题?有趣的是,当我删除除背景之外的所有代码时,它可以工作!!!

【问题讨论】:

  • 发布谁的错误不仅仅是它的一部分
  • post error logcat 10 到 20 行,通常是 logcat 中的红色部分
  • @Hamad 日志中显示的这两行错误 cat: 06-07 15:02:07.048: E/dalvikvm-heap(1657): 9007416-byte external allocation too large for this process. 06-07 15:02:07.098: E/GraphicsJNI(1657): VM 不允许我们分配 9007416 字节
  • 请记住,旧设备的内存可能有限。考虑使用较小的图像作为背景。毕竟,被拉伸后,它会给出相同的模糊效果
  • @user2750644:“问题是,模拟器不支持大内存。已修复!!!”:不要那么肯定。正如 Der Golem 所指出的,不同的设备和 Android 版本将具有有限的内存来处理图像等内容。仅仅因为它适用于您的设备并不意味着它适用于所有设备。

标签: android xml android-layout


【解决方案1】:

检查您的 @drawable 部分,即您用于此布局的图像大小 - 解码位图时 VM 内存不足。缩小图片尺寸。

编辑

我从您的 logcat 中看到
您正在泄漏资源(很可能是 Drawable 对象)。欲了解更多信息,请参阅tools in What Android tools and methods work best to find memory/resource leaks?

【讨论】:

  • 我试图删除背景并运行,但仍然弹出相同的错误。
  • @user2750644 请发布 logcat 异常
猜你喜欢
  • 2018-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
相关资源
最近更新 更多