ANDROID开发之问题积累及解决方案(二)

错误:“Binary XML file line # : Error inflating class”

原因:此异常是布局文件中有错引起的,那么返回到布局文件中看看。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ImageView 
        android:id="@+id/disclosureImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"/>
    
    <TextView 
        android:id="@+id/contentText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/disclosureImg"/>
    

</RelativeLayout>

在imageview处有个黄感叹号,鼠标放上去显示“[Accessibility] Missing contentDescription attribute on image”,就是说图片缺少文本说明。。。。,找到地方就知道怎么办了,缺少说明就给他加一个嘛。

android:contentDescription="@string/icon_description"

加上这个属性后问题就解决了,so。。。这些小细节需多注意,尽量避免这样的错吧~

另:也可参考这位朋友的方案——Android运行时异常“Binary XML file line # : Error inflating class”

posted @ 2016-03-18 10:28  彳亍者  阅读(166)  评论(0编辑  收藏  举报