[問題] 自定義的 widget

看板AndroidDev作者 (奧丁2008)時間13年前 (2012/08/21 17:09), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
自定義了一個 ListView 的 Widget 錯誤是發生在 setContentView 時 而我的 layout 如下 -------------------------------------------------------------- <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <demo.my.widget.myListView android:id="@+id/android:list" android1:layout_width="match_parent" android1:layout_height="wrap_content" /> </LinearLayout> -------------------------------------------------------------- 可是會出現這樣的錯誤訊息 demo.my.widget.myListView failed to instantiate. 堆疊的最後一個是這個 java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.RelativeLayout 試過 Clean... 沒輒 我自己定義的 ListView Widget 是放在 demo.my.widget 下 就如同錯誤訊息裡的那個 package name 而程式是在 demo.my.activity 這個 package 裡 一直無解,懇請提供方向,感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.251.154.220

08/21 19:13, , 1F
我猜有可能是id的問題,改個普通的id試看看
08/21 19:13, 1F

08/21 21:40, , 2F
http://tinyurl.com/ykczs6d 這個項目的最後一行
08/21 21:40, 2F

08/21 21:40, , 3F
Descendants of these classes are not supported.
08/21 21:40, 3F

08/21 21:44, , 4F
不過 錯誤訊息是說轉型失敗....
08/21 21:44, 4F
文章代碼(AID): #1GCr0ot3 (AndroidDev)