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 手機的時候報錯,錯誤就是以上顯示的。
這個時候只需要這只include的width和height屬性就好就像這樣
<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://blog.51cto.com/poarry/1737778
總結
以上是生活随笔為你收集整理的Binary XML file line #2: You must supply a layout_height attribute inflate的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用好href的target, base
- 下一篇: My linux