加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 08:45:09 所属栏目:百科 来源:网络整理
导读:Android 开发中遇到的奇葩问题之一: java.lang.NullPointerException ,java.lang.RuntimeException:Binary XML file line #2: You must supply a layout_height attribute inflate, 遇到这个问题说明你在非主流上测试,或者说是在部分模拟器上测试,或者

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

java.lang.NullPointerException,java.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读