0
I have a Fragment that misses every time 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)
Even putting these checks on onCreateOptionMenu, generates the same error.
This error is generated when I click on Location in 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;
}
You say it is an error when you start Fragment but then you say it is when you click the button. Which of the two is?
– ramaral
It’s when I click the button and, soon gives error! I’m sorry for the confusion!
– António Macave
The error indicates that the variable
map
is void.– ramaral
Yeah! But, she’s been initialized! So much so that when I start the app, it opens normally, the problem is when I click on those buttons! I don’t understand what’s wrong!
– António Macave
Add the full code relevant to your problem to the question
– Leonardo Lima
I added the Bottomnavigationview Listener, I don’t know yet I need to add something else.
– António Macave