[問題] jsoup執行緒問題
小弟最近在學jsoup
後來利用java測試jsoup成功了
問題是要轉來Android遇到麻煩
想直接把jsoup code 寫在Button OnClickListener裡面
上網查需要用thread
直接在Button監聽事件中寫入
new Thread(new Runnable() {
@Override
public void run() {
//jsoup code
}
}).start();
這樣的程式碼
有錯嗎
怎麼測試都是按下按鈕後閃退
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.230.245.168
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1491644559.A.25F.html
推
04/08 18:10, , 1F
04/08 18:10, 1F
FATAL EXCEPTION: Thread-4
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6891)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1083)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:5205)
at android.view.View.invalidateInternal(View.java:13656)
at android.view.View.invalidate(View.java:13620)
at android.view.View.invalidate(View.java:13604)
at android.widget.TextView.checkForRelayout(TextView.java:7355)
at android.widget.TextView.setText(TextView.java:4480)
at android.widget.TextView.setText(TextView.java:4337)
at android.widget.TextView.setText(TextView.java:4312)
at .page2$3$1.run(page2.java:74)
at java.lang.Thread.run(Thread.java:761)
這樣是錯在哪裡呢
※ 編輯: bruce0428 (36.230.245.168), 04/08/2017 18:17:00
→
04/08 18:29, , 2F
04/08 18:29, 2F
→
04/08 18:30, , 3F
04/08 18:30, 3F
推
04/08 19:43, , 4F
04/08 19:43, 4F
→
04/08 21:54, , 5F
04/08 21:54, 5F
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章