我想更改菜单中项目的标题,但是我收到错误,这是日志:
jhipster-uml
我不明白为什么它会对空对象引用。
这是java文件:
yo jhipster:entity
然后;
E: FATAL EXCEPTION: main
Process: com.locateit.antholife.locateit, PID: 18329
java.lang.NullPointerException: Attempt to invoke interface method 'android.view.MenuItem android.view.MenuItem.setTitle(java.lang.CharSequence)' on a null object reference
at com.locateit.antholife.locateit.Main2Activity.onPrepareOptionsMenu(Main2Activity.java:786)
at android.app.Activity.onPreparePanel(Activity.java:3150)
at android.support.v4.app.FragmentActivity.onPrepareOptionsPanel(FragmentActivity.java:530)
at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:519)
at android.support.v7.view.WindowCallbackWrapper.onPreparePanel(WindowCallbackWrapper.java:93)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onPreparePanel(AppCompatDelegateImplBase.java:297)
at android.support.v7.view.WindowCallbackWrapper.onPreparePanel(WindowCallbackWrapper.java:93)
at android.support.v7.app.ToolbarActionBar$ToolbarCallbackWrapper.onPreparePanel(ToolbarActionBar.java:567)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:455)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:133)
感谢您的帮助! :)
XML文件:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.vue, menu);
this.menu = menu;
return true;
答案 0 :(得分:0)
这是一个视图导航所以问题解决了谢谢!我们必须定义我们说的菜单..! :
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
Menu nv = navigationView.getMenu();
MenuItem item = nv.findItem(R.id.nav_distance);