举例说明android编程中遇到的关于android.view.InflateException错误的原因及解决办法

在LogCat中错误提示如下:

 

03-20 19:04:48.109: E/AndroidRuntime(12664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.waterfall/com.my.waterfall.WaterfallStreamTest}: android.view.InflateException: Binary XML file line #2: Error inflating class com.my.LazyScrollView

 

 

03-20 19:04:48.109: E/AndroidRuntime(12664): Caused by: java.lang.ClassNotFoundException: com.my.LazyScrollView in loader dalvik.system.PathClassLoader[/data/app/com.my.waterfall-1.apk]

 

从中可以找到造成的原因是在我自定义的一个xml文件(如下所示)中把一个类所在的文件夹的目录写错了

 

<?xml version="1.0" encoding="utf-8"?>
<com.my.waterfall.LazyScrollView xmlns:android="
http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/waterfall_scroll"
    >
    <LinearLayout
        android:id="@+id/waterfall_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white"
        />
</com.my.waterfall.LazyScrollView>

上面的粗体是正确的写法。

下面的粗体是错误的写法:

<?xml version="1.0" encoding="utf-8"?>
<com.my.LazyScrollView xmlns:android="
http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/waterfall_scroll"
    >
    <LinearLayout
        android:id="@+id/waterfall_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white"
        />
</com.my.LazyScrollView>

 

有时造成错误的原因或许是资源放的地方不对:

例如应该把放在 drawable-hdpi/目录下的资源,放在了drawable-mdpi/目录下或者drawable-ldpi/目录下。这种错误的解决办法就是把资源重新copy到drawable-hdpi/下;另外还有一种解决办法:在res/下建一目录drawable/,将drawable-mdpi/下所有的资源文件都拷贝到drawable/下即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值