Note that there are some explanatory texts on larger screens.

plurals
  1. POalert dialog null inside of listener method, null pointer
    primarykey
    data
    text
    <p>i put an alert dialog inside a custom listener that i created, it is like a onClick listener. the listener is called when an event occurs in another class. </p> <p>why the null pointer when i put the alert dialog code inside of the listener call back method? how can i fix this? and more importantly. why do i get the null pointer?</p> <p>the listener calls the callback method onResultReturned in this Android java class, and when that happens i wanted the alert dialog to appear. </p> <p>the strange thing is that this alert dialog code works fine outside of my callback method, like when i put it in the onCreate method</p> <p>the activity i am in is StartActivity and the method onReturnResult is in this class, the other activity called, Synchronizer is where the interface for the listener is located.</p> <p>stack trace;</p> <pre><code>09-27 16:08:42.300: E/AndroidRuntime(7195): FATAL EXCEPTION: main 09-27 16:08:42.300: E/AndroidRuntime(7195): java.lang.NullPointerException 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:132) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.app.AlertDialog$Builder.&lt;init&gt;(AlertDialog.java:359) 09-27 16:08:42.300: E/AndroidRuntime(7195): at .StartActivity.onResultReturned(StartActivity.java:100) 09-27 16:08:42.300: E/AndroidRuntime(7195): at .Synchronizer$SendOutMsgAndPack$2.run(Synchronizer.java:159) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.os.Handler.handleCallback(Handler.java:605) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.os.Handler.dispatchMessage(Handler.java:92) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.os.Looper.loop(Looper.java:137) 09-27 16:08:42.300: E/AndroidRuntime(7195): at android.app.ActivityThread.main(ActivityThread.java:4424) 09-27 16:08:42.300: E/AndroidRuntime(7195): at java.lang.reflect.Method.invokeNative(Native Method) 09-27 16:08:42.300: E/AndroidRuntime(7195): at java.lang.reflect.Method.invoke(Method.java:511) 09-27 16:08:42.300: E/AndroidRuntime(7195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) </code></pre> <p>code for my onResultReturned callback method, which is called about 4 to 5 seconds after the activity is created usually</p> <pre><code> @Override public void onResultReturned(int result) { // build allertdialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(StartActivity.this); // set title alertDialogBuilder.setTitle("update status"); //set allert message alertDialogBuilder .setMessage("update success") .setCancelable(false) .setPositiveButton("OK",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity //StartActivity.this.finish(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload