我正在创建onCreateOptionsMenu我收到了菜单inflater异常。我已尝试过本网站和其他来源提供的所有内容。其实我正在关注Android网站上提供的记事本教程。我尝试从头开始在我的应用程序中创建一个菜单,它给出了同样的错误。
下面的简单菜单代码
private int searchBtnId = Menu.FIRST;
private int group1Id = 1;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(group1Id,searchBtnId ,searchBtnId,"Search");
//menu.setGroupVisible(1, false);
openOptionsMenu();
return true;
}
02-04 12:09:18.544: E/AndroidRuntime(396): FATAL EXCEPTION: main
02-04 12:09:18.544: E/AndroidRuntime(396): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.demo.notepad2/com.android.demo.notepad2.NoteEdit}: java.lang.NullPointerException
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.os.Looper.loop(Looper.java:123)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-04 12:09:18.544: E/AndroidRuntime(396): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 12:09:18.544: E/AndroidRuntime(396): at java.lang.reflect.Method.invoke(Method.java:507)
02-04 12:09:18.544: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-04 12:09:18.544: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-04 12:09:18.544: E/AndroidRuntime(396): at dalvik.system.NativeStart.main(Native Method)
02-04 12:09:18.544: E/AndroidRuntime(396): Caused by: java.lang.NullPointerException
02-04 12:09:18.544: E/AndroidRuntime(396): at com.android.demo.notepad2.NoteEdit.onCreate(NoteEdit.java:32)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-04 12:09:18.544: E/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-04 12:09:18.544: E/AndroidRuntime(396): ... 11 more