我的应用程序中有 2 个活动,在第二个活动中,我有代码在单击“关于”android 操作栏图标时运行。在第一个活动中,我有相同的操作栏菜单项,我想再次调用这个“关于”方法,但是当我点击它时,我有空指针异常。有人帮忙吗?
这是第二个活动中定义的方法 - JokeDetailsActivity
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();
}
当我在第一个活动中调用它时
case R.id.action_about:
JokeDetailsActivity jd = new JokeDetailsActivity();
jd.aboutMe();
return true;
}
这就是我得到的错误
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.<init>(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)