AsyncTask错误,请帮我查一下

时间:2015-05-15 05:57:12

标签: android

05-15 13:33:04.121: E/AndroidRuntime(22516): FATAL EXCEPTION: pool-7-thread-5
05-15 13:33:04.121: E/AndroidRuntime(22516): Process: my.com.newpagesv2, PID: 22516
05-15 13:33:04.121: E/AndroidRuntime(22516): java.lang.RuntimeException: An error occured while executing doInBackground()
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.os.AsyncTask$3.done(AsyncTask.java:300)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.lang.Thread.run(Thread.java:841)
05-15 13:33:04.121: E/AndroidRuntime(22516): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7081)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1107)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.ViewGroup.invalidateChild(ViewGroup.java:4529)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.View.invalidate(View.java:11809)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.View.invalidate(View.java:11750)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.widget.ImageView.invalidateDrawable(ImageView.java:211)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:393)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.graphics.drawable.Drawable.setVisible(Drawable.java:624)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.widget.ImageView.onDetachedFromWindow(ImageView.java:1265)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.View.dispatchDetachedFromWindow(View.java:13557)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2791)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4236)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.widget.AbsListView.resetList(AbsListView.java:2388)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.widget.ListView.resetList(ListView.java:527)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.widget.ListView.setAdapter(ListView.java:468)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at my.com.newpagesv2.BrowseByAlp$getJsonMoreAlpData.doInBackground(BrowseByAlp.java:356)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at my.com.newpagesv2.BrowseByAlp$getJsonMoreAlpData.doInBackground(BrowseByAlp.java:1)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-15 13:33:04.121: E/AndroidRuntime(22516):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-15 13:33:04.121: E/AndroidRuntime(22516):    ... 3 more

3 个答案:

答案 0 :(得分:1)

像这样更新你的UI。

yourActivity.runOnUiThread(new Runnable() {  
    @Override  
    public void run() {  
       // update your ui here  
    }  
 });  

我希望它能帮到你..!

答案 1 :(得分:0)

  

13:33:04.121:E / AndroidRuntime(22516):引起:android.view.ViewRootImpl $ CalledFromWrongThreadException:只有创建视图层次结构的原始线程才能触及其视图。

您正在使用doInBackground方法更新用户界面。请确保doInBackground中没有ui代码。您应该只在onPostExecute

中修改UI

只要您需要访问UI,请将代码放入onPostExecute方法。

答案 2 :(得分:0)

runOnUiThread(new Runnable() {  
    @Override  
    public void run() {  
       // update your ui here  
    }  
 });