Re: [問題] 新手發問btn遇到nullPoint
※ 引述《relievezaoc (shu)》之銘言:
: XML:http://ppt.cc/hWRf
: main.java:http://ppt.cc/XOJq
: logcat:http://ppt.cc/OKG4
: 新手爬文結果發現 出現這種問題通常都是XML有問題 或是findviewbyid沒抓到..
: 不過我只有一個txtview 跟一個btn也有問題
: 有clean也是一樣~"~
: java裡 我有寫個
: //ii
: public void click (View v){...} 的寫法
: 是google有這種偷吃步的方式 直接在xml的btn 給他onclick
: 我用這種方式好像因為沒有去抓btn的r.id..所以就正常可以用...
: whyyy~~~@_@~~
: 想請問是哪邊該修改呢?
FragmentTransaction.commit() 文件:
Schedules a commit of this transaction.
The commit does not happen immediately;
it will be scheduled as work on the main thread to be done
the next time that thread is ready.
commit() 不會馬上把 PlaceholderFragment 加進去,而會等到下一次
main thread ready,以你的程式碼來說,至少要等到 Activity.onCreate() 結束之後
才有機會執行。所以你在 Activity.onCreate() 裡嘗試存取該 fragment 或 fragment
底下的 view 都會失敗。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.21.200
※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1396294140.A.915.html
推
04/01 22:55, , 1F
04/01 22:55, 1F
→
04/01 22:56, , 2F
04/01 22:56, 2F
→
04/01 22:56, , 3F
04/01 22:56, 3F
→
04/01 22:57, , 4F
04/01 22:57, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):