2011年10月30日 星期日

[Android] CalledFromWrongThreadException

Error Message
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1102)
Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:2705)
at android.view.ViewRoot.invalidateChild(ViewRoot.java:574)
at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:600)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:2450)
at android.view.View.invalidate(View.java:4945)
at android.widget.TextView.checkForRelayout(TextView.java:5442)
at android.widget.TextView.setText(TextView.java:2693)
at android.widget.TextView.setText(TextView.java:2561)
at android.widget.TextView.setText(TextView.java:2536)
at com.yellow.android.TextActivity$1.onProgressUpdate(TextActivity.java:40)
at com.yellow.android.TextActivity$1.doInBackground(TextActivity.java:32)
at com.yellow.android.TextActivity$1.doInBackground(TextActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
 ... 4 more



Solution

Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

一般是因為沒有在 UI thread 執行關於 UI 上的操作 所以會利用 AsyncTask

原以為是因為在 AsyncTask 中使用 Thread.sleep() 而發生的 exception

但重寫後並不是

所以目前不確定發生的情況與真正原因


沒有留言:

張貼留言