I have a Google Maps based application and it was working with the methods getMap(), now with the new model getMapAsync, I'm having troubles when I want to clear or use in general the GoogleMap object,
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.clear()' on a null object reference.
I'm using a Fragment.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_passenger_page1,
container, false);
MapFragment fm = (MapFragment) mainActivity.getFragmentManager().findFragmentById(R.id.map);
fm.getMapAsync(this);
...
}
the problem is here when I use:
@Override
public void onResume() {
mMap.clear();
if (listMarkers.size() > 0)
{
setMarker(listMarkers);
}
super.onResume();
}
This function is called every time the App opens, and says that mMap is null.
Please help me.