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)
my code
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;
}
}
i am starting thread this task after another dialog placed in signleton class is stopped and then i am trying to start another progress dialog inside asyncTask so this second dialog onPreexecute开发者_如何学运维 raise looper error any one guide me how to get rid of this issue?
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();**
and call the following inside ur Async Task
mHandler.post(Example);
hope u understand.
As the other already said. You cannot edit the UI form the AsyncTask's doInBackground() method directly. But you can use onProgressUpdate(Progress...) and publishProgress(Progress...) to update the UI. So you can stick to the AsyncTask concept without using a handler explicitly.
You can't modify the UI from the asynctask while its running - only in pre or post execute.
You could use a handler in your main class and send the updates to that if you need to update ui components.
精彩评论