I am using async task in my application.I am starting a progress dialog on pre-execute and in doInBackground i'm calling a function which will return the current location from geocoder.If the current place is not available i'm showing a dialog box to manually enter the place.But it is getting crashed when the dialog comes.i'm not even able to use a toast in that function which results a force close.Can any1 have the solution for this issue..? Please help.. This is the error that i'm getting..
01-03 09:45:36.216: E/AndroidRuntime(452): FATAL EXCEPTION: AsyncTask #1
01-03 09:45:36.216: E/AndroidRuntime(452): java.lang.RuntimeException: An error occured while executing doInBackground()
01-03 09:45:36.216: E/AndroidRuntime(452): at android.os.AsyncTask$3.done(AsyncTask.java:200)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-03 09:45:36.216: E/AndroidRuntime(452): at java.lang.Thread.run(Thread.java:1019)
01-03 09:45:36.216: E/AndroidRuntime(452): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
01-03 09:45:36.216: E/AndroidRuntime(452): at android.os.Handler.<init>(Handler.java:121)
01-03 09:45:36.216: E/AndroidRuntime(452): at android.widget.Toast.<init>(Toast.java:68)
01-03 09:45:36.216: E/AndroidRuntime(452): at android.widget.Toast.makeText(Toast.java:231)
my async task is this.
private class UpdateCity extends AsyncTask<String, Void, Void> {
ProgressDialog dialog = new ProgressDialog(this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Please wait for few seconds...");
this.dialog.setTitle("");
this.dialog.show();
}
@Override
protected Void doInBackground(final String... args) {
checkCity(Cplacename);//my function
return null;
}
@Override
protected void onPostExecute(final Void unused) {
this.dialog.dismiss();
}
}