A Fragment (of the map) that lies within an activity, when I click on
From Activity, can you change properties of the map that is in the Fragment?
By clicking on the Navigation Drawer Map item it performs the following method:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.mapa_nav_drawer) {
MapFragment mf = new MapFragment();
mf.alterarTipoParaSatelite();
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
This is the method to change the MapFragmentType () method of MapFragment
public void alterarTipoParaSatelite() {
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
But by clicking, it gives me the following error:
Process: mz.co.bm.exemplo, PID: 18163
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setMapType(int)' on a null object reference
at mz.co.bm.exemplo.MapFragment.alterarTipoParaSatelite(MapFragment.java:195)
at mz.co.bm.exemplo.MainActivity.onNavigationItemSelected(MainActivity.java:84)
at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:154)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342)
at android.view.View.performClick(View.java:5637)