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)
答案 0 :(得分:11)
我认为你使用的是一些东西
Toast.makeText(this, "Text", Toast.LENGTH_SHORT).show();
或使用doInBackground()
方法中的视图。
如果您想使用它们,请在onPostExecute()
中使用它。
答案 1 :(得分:3)
只有创建视图层次结构的原始线程才能触及其视图
您无法从后台线程更改UI。
UI在主线程上运行,您的ASyncTask在其自己的线程上运行。
如果您想从其他线程通知UI更改,则必须使用处理程序。
看看:
答案 2 :(得分:3)
您正在从另一个线程上运行的方法Views
修改doInBackground
。在android中,这是禁止的,而是应该仅从onPostExecute
方法修改视图。
答案 3 :(得分:1)
您必须将更新ui的后台任务部分移动到主线程上。
答案 4 :(得分:1)
此行生成错误
E/AndroidRuntime(1086): Caused by:Only the original thread that created
a view hierarchy can touch its views".
您应该尝试显示Asyntack doInBackGround()
方法。
答案 5 :(得分:1)
您必须使用UI线程的部分,或者您可以使用上下文中提供的runOnUIThread方法
答案 6 :(得分:-1)
这样做:而不是使用asynctask使用线程。 在这里:
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();