Binary XML file line #2: You must supply a layout_height attribute inflate

Android开发中遇到的奇葩问题之一:

java.lang.NullPointerExceptionjava.lang.RuntimeException:Binary XML file line #2: You must supply a layout_height attribute inflate,

遇到这个问题说明你在非主流上测试,或者说是在部分模拟器上测试,或者是在写布局文件的时候少了什么东西,比如是写成这样的:


<Button xmlns:android="http//schemas.android.com/apk/res/android"
android:layout_width="30dp"
android:layout_height="10dp"
android:text="test" />

那你只是需要改成这样的 (区别是http后面少了冒号哈哈哈哈哈哈)

<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="30dp"
android:layout_height="10dp"
android:text="test" />


或者这样的错误

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="20dp"
android:layout_height="5dp"
android:id="@+id/tablerow01">

其他的遇到的情况是如果不是在include的时候出现的那么请关闭浏览器标签,重新找解决方案,否则请听我重现我的bug

情景重现:我在添加布局的时候是这么写的

<include
android:id="@+id/test"
layout="@layout/activity_base"></include>

然后,在大部分的测试机上跑起来都是正常的,当用到OPPO A31 手机的时候报错,错误就是以上显示的。

这个时候只需要这只includewidthheight属性就好就像这样

<include
android:id="@+id/test"
layout="@layout/activity_base"
android:layout_width="match_parent"
android:layout_height="30dp"></include>

PS :如果写成如下情况也还是原来的错误

<include
android:id="@+id/test"
layout="@layout/activity_base"
android:layout_width="match_parent"
android:layout_height="@dimen/fab_margin"></include>

这个错误具体的原理我百思不得其解,如有解决希望多交流([email protected]

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念