2011-05-18 72 views
0
05-18 17:53:35.318: WARN/System.err(474): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
05-18 17:53:35.349: WARN/System.err(474):  at android.os.Handler.<init>(Handler.java:121) 
05-18 17:53:35.349: WARN/System.err(474):  at android.app.Dialog.<init>(Dialog.java:101) 
05-18 17:53:35.358: WARN/System.err(474):  at android.app.AlertDialog.<init>(AlertDialog.java:63) 
05-18 17:53:35.358: WARN/System.err(474):  at android.app.ProgressDialog.<init>(ProgressDialog.java:80) 
05-18 17:53:35.377: WARN/System.err(474):  at android.app.ProgressDialog.<init>(ProgressDialog.java:76) 
05-18 17:53:35.377: WARN/System.err(474):  at com.Utils.SProgress.StartProgress(SProgress.java:42) 
05-18 17:53:35.387: WARN/System.err(474):  at com.FindMe.DisplayAtms$Asyctast.onPreExecute(DisplayAtms.java:880) 
05-18 17:53:35.400: WARN/System.err(474):  at android.os.AsyncTask.execute(AsyncTask.java:391) 
05-18 17:53:35.400: WARN/System.err(474):  at com.FindMe.DisplayAtms.LoadFunction(DisplayAtms.java:141) 
05-18 17:53:35.408: WARN/System.err(474):  at com.FindMe.MyApplication$AsyncATMS.doInBackground(MyApplication.java:207) 
05-18 17:53:35.419: WARN/System.err(474):  at com.FindMe.MyApplication$AsyncATMS.doInBackground(MyApplication.java:1) 
05-18 17:53:35.419: WARN/System.err(474):  at android.os.AsyncTask$2.call(AsyncTask.java:185) 
05-18 17:53:35.427: WARN/System.err(474):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
05-18 17:53:35.438: WARN/System.err(474):  at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
05-18 17:53:35.438: WARN/System.err(474):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 
05-18 17:53:35.447: WARN/System.err(474):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 
05-18 17:53:35.458: WARN/System.err(474):  at java.lang.Thread.run(Thread.java:1096) 

我的代碼運行AsyncTask時looper錯誤?

Another function() 
{ 

anotherSingletonprogressdiloag.hide(); 

.new Asyctast().execute(); 


} 




public class Asyctast extends AsyncTask<Void, Object, Void> 
    { 

    private ProgressDialog dialog = new ProgressDialog(DisplayAtms.this); 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      dialog.show(); 

     } 


     @Override 
     protected void onProgressUpdate(final Object... args) { 
      super.onProgressUpdate(args); 
      if ((Boolean) args[0]) { 
       Toast.makeText(DisplayAtms.this, args[1].toString(), 
         Toast.LENGTH_LONG).show(); 
      } 
     } 

     @Override 
     protected Void doInBackground(Void... arg0) { 
      Log.d("Asynctask", ""+arg0); 


       publishProgress(true,"sd sdfsdf"); 


       return null; 

     } 

    } 

我開始放在signleton類另一個對話框後,這個任務被停止線程,然後我試圖啓動另一個進程中的AsyncTask 對話框,本次對話onPreexecute提高尺蠖錯誤任何一個人指導我如何擺脫這個問題?

回答

1
private final Runnable Example= new Runnable() 
    { 
     public void run() 
     { 
      try 
      { 
       //put ur code which cause the looper error    
      } 
      catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
     } 
    }; 
    private final Handler mHandler = new Handler();** 

,並呼籲烏爾異步任務內的下列

mHandler.post(Example); 

希望你明白。

+0

是的,我得到它我在毛孔上使用runonuiThread(exampleRunable)執行並將該代碼移動到可替代的那個runnable。謝謝 – UMAR 2011-05-18 13:01:20

+0

不要給我投票答案。 – Kakey 2011-05-19 05:26:46

0

您不能在asynctask運行時修改UI - 只能在執行前或執行後執行。

如果您需要更新ui組件,您可以在主類中使用處理程序並將更新發送到該處理程序。

+0

可以請你在這裏指導我如何將它移動到那個處理器類的東西? – UMAR 2011-05-18 12:15:14