在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/下即可。