[Solved] Google Maps Marker giving a null reference on Android [duplicate]


Based on the logcat output that you have provided, the first thing you need to address is the fact that your mMap variable is null.

My guess is that you’re either calling displayLocation() before the onMapReady(...) callback has fired, or your class isn’t equipped to handle the callback at all.

If you’re using the Google Map Fragment, the basic approach is as follows:

In your onCreate(...) method:

((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapFragment)).getMapAsync(this);

Make sure your class implements com.google.android.gms.maps.OnMapReadyCallback.

Then, override the onMapReady(GoogleMap googleMap) method and set your mMap variable.

@Override
public void onMapReady(GoogleMap googleMap){

mMap = googleMap;

//Do whatever else you need to with the map...
}

Make sure you don’t use mMap until it has been set, and you should be able to add your markers, and do other stuff without issue.

1

solved Google Maps Marker giving a null reference on Android [duplicate]