Note that there are some explanatory texts on larger screens.

plurals
  1. POnull pointer exception calling a method
    text
    copied!<p>I have 2 activities in my app, in the second one I have the code to run when the "about" android action bar icon is clicked. In the first activity I have the same action bar menu items and I want to call this "about" method again, however when I click that, I have null Pointer exception. Anyone help ?</p> <p>this is the method defined in the second activity - JokeDetailsActivity</p> <pre><code>public void aboutMe(){ AlertDialog.Builder dialog = new AlertDialog.Builder(JokeDetailsActivity.this); dialog.setTitle("About"); dialog.setMessage("Hello! I'm ..., the creator of this application." +"If there is any bug found please freely e-mail me. "+ "\n ...." ); dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog.show(); } </code></pre> <p>when I call it in the first activity</p> <pre><code>case R.id.action_about: JokeDetailsActivity jd = new JokeDetailsActivity(); jd.aboutMe(); return true; } </code></pre> <p>thats the error I'm getting</p> <pre><code>09-12 20:11:42.748: E/AndroidRuntime(1032): FATAL EXCEPTION: main 09-12 20:11:42.748: E/AndroidRuntime(1032): java.lang.NullPointerException 09-12 20:11:42.748: E/AndroidRuntime(1032): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140) 09-12 20:11:42.748: E/AndroidRuntime(1032): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103) 09-12 20:11:42.748: E/AndroidRuntime(1032): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143) 09-12 20:11:42.748: E/AndroidRuntime(1032): at android.app.AlertDialog$Builder.&lt;init&gt;(AlertDialog.java:360) 09-12 20:11:42.748: E/AndroidRuntime(1032): at ie.myjokes.JokeDetailsActivity.aboutMe(JokeDetailsActivity.java:293) 09-12 20:11:42.748: E/AndroidRuntime(1032): at ie.myjokes.CategoryActivity.onOptionsItemSelected(CategoryActivity.java:140) 09-12 20:11:42.748: E/AndroidRuntime(1032): at android.app.Activity.onMenuItemSelected(Activity.java:2548) </code></pre>
 

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