0
我有一個按鈕視圖,我想禁止與創建它的線程不同的線程。我收到以下錯誤:Android:基於從其他線程觸發的事件更新GUI
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: org.pcgod.mumbleclient, PID: 21302
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:8129)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1258)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:5430)
at android.view.View.invalidateInternal(View.java:13927)
at android.view.View.invalidate(View.java:13863)
at android.view.View.invalidateDrawable(View.java:18097)
at android.widget.TextView.invalidateDrawable(TextView.java:6177)
at android.graphics.drawable.DrawableContainer.invalidateDrawable(DrawableContainer.java:377)
at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:844)
at android.graphics.drawable.Drawable.setVisible(Drawable.java:1575)
at android.graphics.drawable.DrawableContainer.selectDrawable(DrawableContainer.java:448)
at android.graphics.drawable.StateListDrawable.onStateChange(StateListDrawable.java:104)
at android.graphics.drawable.Drawable.setState(Drawable.java:1413)
at android.view.View.drawableStateChanged(View.java:18264)
at android.widget.TextView.drawableStateChanged(TextView.java:4505)
at android.view.View.refreshDrawableState(View.java:18328)
at android.view.View.setEnabled(View.java:8018)
at android.widget.TextView.setEnabled(TextView.java:1895)
at org.pcgod.mumbleclient.Matar.TcpClient.readMessageFromServer(TcpClient.java:103)
at org.pcgod.mumbleclient.Matar.home$requestsQueueConnectTask.doInBackground(home.java:297)
at org.pcgod.mumbleclient.Matar.home$requestsQueueConnectTask.doInBackground(home.java:276)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
這裏是我的代碼:
requestBTN = (Button) findViewById(R.id.requestBTN);
new requestsQueueConnectTask().execute(""); //handle requests queueing
如何解決此問題?我需要根據從其他線程觸發的事件更新GUI(Asynctask
)