我正在扩展 AsyncTask 并在我的 doInBackground() 中使用 findViewById 获得一个按钮视图,当我调用 button.performClick() 时,我的应用程序崩溃了。
知道为什么吗?
这是日志猫:
E/AndroidRuntime(604): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(604): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(604): at android.os.AsyncTask$3.done(AsyncTask.java:278)
E/AndroidRuntime(604): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime(604): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime(604): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime(604): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime(604): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/AndroidRuntime(604): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/AndroidRuntime(604): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(604): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
E/AndroidRuntime(604): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4039)
E/AndroidRuntime(604): at android.view.ViewRootImpl.playSoundEffect(ViewRootImpl.java:3610)
E/AndroidRuntime(604): at android.view.View.playSoundEffect(View.java:13103)
E/AndroidRuntime(604): at android.view.View.performClick(View.java:3510)