I have problem showing AlertDialog. Whenever I run the code, the application become not responding and force close. Herewith my code:
public void displayList(View view){
new AsyncTask<String, Void, List<Address>>() {
protected List<Address> doInBackground(String... params) {
/* some operations */
return null;
}
protected void onPostExecute(List<Address> result) {
if(result.size() == 0){
/* do something */
} else {
/* some code */
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(sometext);
alert.show();
}
}
}.execute(destination);
}
and here is my logCat
11-20 20:26:56.848: E/AndroidRuntime(29789): FATAL EXCEPTION: main 11-20 20:26:56.848: E/AndroidRuntime(29789): java.lang.NullPointerException 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.app.AlertDialog$Builder.(AlertDialog.java:359) 11-20 20:26:56.848: E/AndroidRuntime(29789): at com.ceria.tuntun.MainActivity$5.onPostExecute(MainActivity.java:201) 11-20 20:26:56.848: E/AndroidRuntime(29789): at com.ceria.tuntun.MainActivity$5.onPostExecute(MainActivity.java:1) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.os.AsyncTask.finish(AsyncTask.java:602) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.os.AsyncTask.access$600(AsyncTask.java:156) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.os.Handler.dispatchMessage(Handler.java:99) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.os.Looper.loop(Looper.java:137) 11-20 20:26:56.848: E/AndroidRuntime(29789): at android.app.ActivityThread.main(ActivityThread.java:4511) 11-20 20:26:56.848: E/AndroidRuntime(29789): at java.lang.reflect.Method.invokeNative(Native Method) 11-20 20:26:56.848: E/AndroidRuntime(29789): at java.lang.reflect.Method.invoke(Method.java:511) 11-20 20:26:56.848: E/AndroidRuntime(29789): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980) 11-20 20:26:56.848: E/AndroidRuntime(29789): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) 11-20 20:26:56.848: E/AndroidRuntime(29789): at dalvik.system.NativeStart.main(Native Method)
I don’t know what this happen. I have used AlertDialog so many times and wonder why this one can’t work.
Thank you
use this..
and if you using AlertDialog in TabHost use below line..