2
06-18 16:50:24.733: W/dalvikvm(1086): threadid=11: thread exiting with uncaught exception (group=0x40015560)
06-18 16:50:24.815: E/AndroidRuntime(1086): FATAL EXCEPTION: AsyncTask #3
06-18 16:50:24.815: E/AndroidRuntime(1086): java.lang.RuntimeException: An error occured while executing doInBackground()
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.lang.Thread.run(Thread.java:1019)
06-18 16:50:24.815: E/AndroidRuntime(1086): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.ViewRoot.checkThread(ViewRoot.java:2932)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.ViewRoot.requestLayout(ViewRoot.java:629)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.requestLayout(View.java:8267)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.requestLayout(View.java:8267)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.requestLayout(View.java:8267)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.requestLayout(View.java:8267)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:257)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.requestLayout(View.java:8267)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.widget.AbsListView.requestLayout(AbsListView.java:1102)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.setFlags(View.java:4641)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.view.View.setVisibility(View.java:3116)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at com.mythrii.tripview.BusFrom$DownloadImageTask.doInBackground(BusFrom.java:274)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at com.mythrii.tripview.BusFrom$DownloadImageTask.doInBackground(BusFrom.java:1)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-18 16:50:24.815: E/AndroidRuntime(1086):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-18 16:50:24.815: E/AndroidRuntime(1086):     ... 4 more
06-18 16:50:30.571: E/WindowManager(1086): Activity com.mythrii.tripview.BusFrom has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4062bcc0 that was originally added here
06-18 16:50:30.571: E/WindowManager(1086): android.view.WindowLeaked: Activity com.mythrii.tripview.BusFrom has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4062bcc0 that was originally added here
06-18 16:50:30.571: E/WindowManager(1086):  at android.view.ViewRoot.<init>(ViewRoot.java:258)
06-18 16:50:30.571: E/WindowManager(1086):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
06-18 16:50:30.571: E/WindowManager(1086):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-18 16:50:30.571: E/WindowManager(1086):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.Dialog.show(Dialog.java:241)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ProgressDialog.show(ProgressDialog.java:107)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ProgressDialog.show(ProgressDialog.java:90)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ProgressDialog.show(ProgressDialog.java:85)
06-18 16:50:30.571: E/WindowManager(1086):  at com.mythrii.tripview.BusFrom.onCreate(BusFrom.java:109)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-18 16:50:30.571: E/WindowManager(1086):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 16:50:30.571: E/WindowManager(1086):  at android.os.Looper.loop(Looper.java:130)
06-18 16:50:30.571: E/WindowManager(1086):  at android.app.ActivityThread.main(ActivityThread.java:3683)
06-18 16:50:30.571: E/WindowManager(1086):  at java.lang.reflect.Method.invokeNative(Native Method)
06-18 16:50:30.571: E/WindowManager(1086):  at java.lang.reflect.Method.invoke(Method.java:507)
06-18 16:50:30.571: E/WindowManager(1086):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-18 16:50:30.571: E/WindowManager(1086):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-18 16:50:30.571: E/WindowManager(1086):  at dalvik.system.NativeStart.main(Native Method)
4

7 回答 7

11

我认为您
Toast.makeText(this, "Text", Toast.LENGTH_SHORT).show();
在方法中使用了类似或使用 Views 的东西doInBackground()

如果你想使用那些在onPostExecute().

于 2012-06-18T11:28:31.133 回答
3

只有创建视图层次结构的原始线程才能接触其视图

您不能从后台线程更改 UI。

UI 在主线程上运行,您的 ASyncTask 在它自己的线程上运行。

如果您想通知 UI 来自另一个线程的更改,您将不得不使用处理程序。

看一眼 :

https://stackoverflow.com/a/5185155/413127

runOnUiThread方法

于 2012-06-18T11:25:24.447 回答
3

您正在从在另一个线程上运行的方法中修改您Views的方法。doInBackground在 android 中这是被禁止的,你应该onPostExecute只修改方法中的视图。

于 2012-06-18T11:26:09.047 回答
1

您必须将更新 ui 的后台任务部分移动到主线程上。

于 2012-06-18T11:25:48.007 回答
1

此行出错

E/AndroidRuntime(1086): Caused by:Only the original thread that created 
a view hierarchy can touch its views".

也许你应该尝试并展示Asyntack doInBackGround()方法。

于 2012-06-18T11:26:36.173 回答
1

您必须将部分分配给 UI 线程,或者您可以使用可从上下文中获得的 runOnUIThread 方法

于 2012-06-18T11:26:53.707 回答
-1

这样做:而不是使用 asynktask 使用线程。它是这样的:

thread = new Thread() 
{
  @Override
  public void run() 
  {
    try
    {
      synchronized(this) 
      {
  runOnUiThread(new Runnable() 
  { 
           @Override
           public void run() 
           {                        
            your code goes here
           }
       });                  
     }
  }
  catch(Exception e)
  {
     e.printStackTrace();
  }         
 };
};
thread.start();    
于 2013-03-22T02:00:55.797 回答