Binary XML file line #6: Error inflating class com.examp..
1). 引用類名問題
自定義了一個View,將用於布局文件xml中(包名com.android.test,類名MyTestView),在XML作為布局元素來布局的話,
必須使用完整路徑名:com.android.test.MyTestView,也就是包名加類名來引用。
正確寫法:
-
<com.android.test.MyTestView
-
android:id="@+id/test"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent" />
-
<MyTestView
-
android:id="@+id/test"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent" />
2).構造函數問題
自定義一個View,派生實現基類View的三個構造函數
View(Context context) //Simple constructor to use when creating a view from code
View(Context context, AttributeSet attrs) //Constructor that is called when inflating a view from XML
View(Context context, AttributeSet attrs, int defStyle) //Perform inflation from XML and apply a class-specific base style
從文檔上的介紹來看,第二個和第三個構造函數對於XML這種引用方式是必須實現的,這三個構造函數應該是在不同的應用場合來實例化
一個View對象。
3).編譯的中間文件沒有清理干凈, 使用Eclipse clean 下.
4).找不到資源文件:因為找不到相關的資源文件,xml 文件隱含有錯誤,確保xml 一定是對的.
這上面四個分析一般會出現前兩種錯誤,一定要檢查好定義的xml 無誤,然后引用類名沒有問題。如果還是會報錯的話, 問題還是應該出現在第二步了。盡管上面四步都檢查過,回頭再仔細看。