[問題] findViewById 無法被實體化

看板AndroidDev作者 (skill)時間11年前 (2012/12/22 12:15), 編輯推噓2(2010)
留言12則, 5人參與, 最新討論串1/1
各位大大好 最近寫了個在一個 relative layout中 把 自定義型別(繼承imageview) 和 TextView 疊起來的功能 但是在程式中 不管是 relative layout 還是 TextView 都沒辦法被實體化 QQ 查了 1551 2 2/10 codemonkey R: [問題] TimePicker一直沒有被實體化(NULL) 看說是 sdk + java jdk更新過後 應該就可以找出問題 但是我還是沒辦法搞定它 (都更新過了) 想請問為什麼無法被實體化呢? 我自己是有想過會不會是物件還沒生成我就把它取值... 但實在是不可能是這樣 orz||| 還望各位高手出手相救 謝謝 以下是主要程式碼 http://ppt.cc/JnIU //問題發生在 onClick 的時候 TextView 一直 null XML file <RelativeLayout ...> <LinearLayout ...> ... <RelativeLayout ...> <packageName.MyImageView android:id="@+id/my_view" ... /> <TextView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:layout_alignBottom="@+id/my_view" android:layout_centerHorizontal="true" android:layout_marginBottom="25dp" android:text="MY name is not godjj" /> </RelativeLayout> </LinearLayout> </RelativeLayout> 抱歉排版有點亂QQ||| 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.163.3.187

12/22 12:34, , 1F
你的 R.id.image 有放在 MyImageView 內嗎?
12/22 12:34, 1F

12/22 12:35, , 2F
你的 findViewById 應放在創立的 Activity 中
12/22 12:35, 2F

12/22 12:36, , 3F
然後接你 MyImageView 的 click event
12/22 12:36, 3F

12/22 12:50, , 4F
一看就有問題 你的MyImageView 就不是VIEWGROUP
12/22 12:50, 4F

12/22 12:51, , 5F
裡面怎麼可能放其他VIEW 而且你也沒把其他東西包到裡面
12/22 12:51, 5F

12/22 12:51, , 6F
感覺你的CODE跟你想做的事情根本對不上
12/22 12:51, 6F

12/23 00:48, , 7F
...............................囧
12/23 00:48, 7F

12/23 00:48, , 8F
..好像問題滿大的orz|||
12/23 00:48, 8F

12/23 00:49, , 9F
我耍笨了 囧|||
12/23 00:49, 9F

12/23 12:02, , 10F
setText請用字串
12/23 12:02, 10F

12/23 19:13, , 11F
我是用字串沒錯
12/23 19:13, 11F

12/24 12:54, , 12F
你在MyImageView裡findViewById找根本不在裡面的id啊
12/24 12:54, 12F
文章代碼(AID): #1GrJFtyn (AndroidDev)