In my app i showing google map version2 in a fragment. but i get Null pointer exception at
mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id
None of these solutions fixed it for me -- but this answer from Mark Murphy (https://code.google.com/p/android/issues/detail?id=77714) did:
Use getChildFragmentManager() to access a nested fragment, not getFragmentManager(). http://developer.android.com/reference/android/support/v4/app/Fragment.html#getChildFragmentManager%28%29
i.e.:
public class MapFragment extends Fragment {
private GoogleMap map;
private SupportMapFragment mapFragment;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle data) {
View view = inflater.inflate(R.layout.map_view, vg, false);
FragmentManager fm = getChildFragmentManager();
mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
initMap();
}
});
}
}