微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

这个错误具体的原理我百思不得其解,如有解决希望多交流(PoarryScript@gmail.com

原文地址:https://www.jb51.cc/xml/295604.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。