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

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

缘由:此异常是布局文件中有错引发的,那么返回到布局文件中看看。布局

<?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”,就是说图片缺乏文本说明。。。。,找到地方就知道怎么办了,缺乏说明就给他加一个嘛。spa

android:contentDescription="@string/icon_description"

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

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

相关文章
相关标签/搜索