在我的asyncTask
doInBackground()
方法中,我想通过敬酒来处理异常。但我不能这样做,这是我得到的例外。这是为什么?PS我可以在onPreExecute()
和中做到这一点onPostExecute()
。
02-04 09:43:45.190: E/AndroidRuntime(19308): FATAL EXCEPTION: AsyncTask #1
02-04 09:43:45.190: E/AndroidRuntime(19308): java.lang.RuntimeException: An error occured while executing doInBackground()
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.os.AsyncTask$3.done(AsyncTask.java:278)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.lang.Thread.run(Thread.java:856)
02-04 09:43:45.190: E/AndroidRuntime(19308): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.os.Handler.<init>(Handler.java:121)
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.widget.Toast$TN.<init>(Toast.java:317)
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.widget.Toast.<init>(Toast.java:91)
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.widget.Toast.makeText(Toast.java:233)
02-04 09:43:45.190: E/AndroidRuntime(19308): at com.xxx.MenuActivity$ImageCount.setView(MenuActivity.java:208)
02-04 09:43:45.190: E/AndroidRuntime(19308): at com.xxx.StringAsyncRetriever.getData(StringAsyncRetriever.java:101)
02-04 09:43:45.190: E/AndroidRuntime(19308): at com.xxx.StringAsyncRetriever.getData(StringAsyncRetriever.java:95)
02-04 09:43:45.190: E/AndroidRuntime(19308): at com.xxx.StringAsyncRetriever.doInBackground(StringAsyncRetriever.java:44)
02-04 09:43:45.190: E/AndroidRuntime(19308): at com.xxx.StringAsyncRetriever.doInBackground(StringAsyncRetriever.java:1)
02-04 09:43:45.190: E/AndroidRuntime(19308): at android.os.AsyncTask$2.call(AsyncTask.java:264)
02-04 09:43:45.190: E/AndroidRuntime(19308): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)