首页 > 其他 > 详细

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

时间:2016-01-23 08:00:39      阅读:276      评论:0      收藏:0      [点我收藏+]

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


本文出自 “知行合一” 博客,请务必保留此出处http://poarry.blog.51cto.com/5970996/1737778

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

原文:http://poarry.blog.51cto.com/5970996/1737778

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!