title: Menu item setTitle
body: <p>I would like to change the title of an item in a menu, but I get an error, here is the log:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I do not understand why it makes to a null object reference..</p>
  
  <p>Here is the java file:</p>
  
  <pre><code>@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;
  </code></pre>
  
  <p>then ; </p>
  
  <pre><code>@Override
  public boolean onPrepareOptionsMenu(Menu menu) {
  
      super.onPrepareOptionsMenu(menu);
      MenuItem titredistance = menu.findItem(R.id.nav_distance);
  
      SharedPreferences sharedPreferences = this.getSharedPreferences(
                              "appSharedPreferences", Context.MODE_PRIVATE);
      String lat1 = sharedPreferences.getString("lat", null);
      String lng1 = sharedPreferences.getString("lng", null);
  
      if (ContextCompat.checkSelfPermission(Main2Activity.this,
              Manifest.permission.ACCESS_FINE_LOCATION)
              == PackageManager.PERMISSION_GRANTED) {
  
          LocationManager locationManager = (LocationManager) 
                                  getSystemService(Context.LOCATION_SERVICE);
  
          Criteria criteria = new Criteria();
  
          Location location = locationManager.getLastKnownLocation(
                                  locationManager.getBestProvider(criteria, false));
  
          if (lat1 != null) {
              if (lng1 != null) {
                  if (location != null) {
  
                      if (ContextCompat.checkSelfPermission(this,
                              Manifest.permission.ACCESS_FINE_LOCATION)
                              == PackageManager.PERMISSION_GRANTED) {
  
                          double latl = location.getLatitude();
                          double lngl = location.getLongitude();
  
                          double lat = Double.parseDouble(lat1);
                          double lng = Double.parseDouble(lng1);
  
                          Location locationA = new Location("point A");
  
                          locationA.setLatitude(lat);
                          locationA.setLongitude(lng);
  
                          Location locationB = new Location("point B");
  
                          locationB.setLatitude(latl);
                          locationB.setLongitude(lngl);
  
                          float distance = locationA.distanceTo(locationB);
                          dfi = Float.toString(distance);
                          titredistance.setTitle
                              ("Distance entre la dernière position de Locate iT et la votre :"
                                                                      + "\n" + dfi + "mètres");
                      }
                  }
              }
          } else {
              titredistance.setTitle("Aucune position de Locate iT enregistrée.");
          }
      }
      return(true);
  }
  </code></pre>
  
  <p>Thanks for the help ! :)</p>
  
  <p>XML file : </p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;group android:checkableBehavior="single"&gt;
      &lt;item android:title="Tâches"&gt;
          &lt;menu&gt;
              &lt;item
                  android:id="@+id/nav_buzz"
                  android:icon="@drawable/buzz"
                  android:title="Faire Vibrer/Sonner Locate iT." /&gt;
              &lt;item
                  android:id="@+id/nav_distance"
                  android:icon="@drawable/distance"
                  android:title="En cours.." /&gt;
              &lt;item
                  android:id="@+id/nav_manage"
                  android:icon="@drawable/ic_menu_manage"
                  android:title="Paramètres." /&gt;
  
          &lt;/menu&gt;
      &lt;/item&gt;
  &lt;/group&gt;
  </code></pre>