Gurvinder Singh Gurvinder Singh - 1 year ago 115
Android Question

getMap() is null in SupportMapFragment in gogole map in andorid fragment

I am using google map in a fragment and getting null when calling getMap(), this is my code:

In my MapViewFragment

private GoogleMap mGoogleMap;

I am getting null at this line, in onCreate() method...

mGoogleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(;

In fragment_map_view file


Please suggest.

Answer Source

I got the reason for it, I think I should post for future readers......

Actually as I GoogleMap was called in a fragment so, in the line..

mGoogleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(;

instead of

getFragmentManager(), getSupportFragmentManager() should be used in fragments.

Corrected one-

mGoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download