I have a Fragment that gives error whenever I start it. It generates the following error:
java.lang.NullPointerException: Attempt to invoke virtual method 'int com.google.android.gms.maps.GoogleMap.getMapType()' on a null object reference
at mz.co.bm.bmtrack.MapFragment.onPrepareOptionsMenu(MapFragment.java:175)
at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:2475)
at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:3295)
at android.support.v4.app.FragmentController.dispatchPrepareOptionsMenu(FragmentController.java:331)
at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:480)
at android.support.v7.view.WindowCallbackWrapper.onPreparePanel(WindowCallbackWrapper.java:98)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onPreparePanel(AppCompatDelegateImplBase.java:359)
at android.support.v7.view.WindowCallbackWrapper.onPreparePanel(WindowCallbackWrapper.java:98)
at android.support.v7.app.ToolbarActionBar$ToolbarCallbackWrapper.onPreparePanel(ToolbarActionBar.java:522)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:456)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:57)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:618)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
EvenputtingthesechecksinonCreateOptionMenu,generatesthesameerror.
This error is generated when I click on Location in the BottomNavigationView. The BottomNavigation Listener is as follows:
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.btm_route:
// TODO
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment, new RotaFragment())
.commit();
return true;
case R.id.btm_localizacao:
// TODO
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment, new MapFragment())
.commit();
return true;
case R.id.btm_fuel:
// TODO
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment, new FuelFragment())
.commit();
return true;
}
return false;
}