AsyncTaskを拡張していて、doInBackground()でfindViewByIdを使用してボタンビューを取得し、button.performClick()を呼び出すとアプリがクラッシュします。
なぜですか?
これはlogcatです:
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)