Error inflating class錯誤

來源:互聯網
上載者:User
09-13 16:24:00.996: ERROR/AndroidRuntime(929): FATAL EXCEPTION: main09-13 16:24:00.996: ERROR/AndroidRuntime(929): android.view.InflateException: Binary XML file line #2: Error inflating class com.android.launcher2.AllApps2D$BackHomeZone09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.view.LayoutInflater.createView(LayoutInflater.java:503)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at com.android.launcher2.AllApps2D.onItemLongClick(AllApps2D.java:264)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.widget.AbsListView.performLongPress(AbsListView.java:1753)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.widget.AbsListView.access$600(AbsListView.java:72)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:1711)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.os.Handler.handleCallback(Handler.java:587)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.os.Handler.dispatchMessage(Handler.java:92)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.os.Looper.loop(Looper.java:123)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.app.ActivityThread.main(ActivityThread.java:4627)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at java.lang.reflect.Method.invokeNative(Native Method)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at java.lang.reflect.Method.invoke(Method.java:521)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at dalvik.system.NativeStart.main(Native Method)09-13 16:24:00.996: ERROR/AndroidRuntime(929): Caused by: java.lang.NoSuchMethodException: BackHomeZone(Context,AttributeSet)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at java.lang.Class.getMatchingConstructor(Class.java:660)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at java.lang.Class.getConstructor(Class.java:477)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     at android.view.LayoutInflater.createView(LayoutInflater.java:475)09-13 16:24:00.996: ERROR/AndroidRuntime(929):     ... 17 more

我遇到這種錯誤有過兩種不同的原因:

1、沒有定義inflate需要的預設建構函式;

2、這是個內部類,需要聲明為static才能inflate;

關於自訂群組件,還需要注意的一點是,如果時內部類,這個類就不能作為layout中的節點的名稱,而必須用view作為節點名,然後加入一個class屬性,值為該內部類的引用,比如launcher中又下面這樣一個例子:

    <view        class="com.android.launcher2.AllApps2D$HomeButton"        android:id="@+id/all_apps_2d_home"        android:tag="all_apps_2d_home"        android:src="@drawable/home_button"        android:background="#FF000000"        android:layout_centerHorizontal="true"        android:layout_alignParentBottom="true"        android:layout_width="wrap_content"        android:layout_height="@dimen/button_bar_height"        android:nextFocusUp="@+id/all_apps_2d_grid"        android:nextFocusDown="@null"        android:nextFocusLeft="@null"        android:nextFocusRight="@null"        />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.