I\'m getting some reports back from user experience through crashlytics giving me an error
Fatal Exception java.lang.NullPointerException
CameraU
I was getting the same error, even though I obtained a non-null GoogleMap object from a MapView. I resolved it with an explicit call to MapsInitializer, even though the documentation says it's not needed.
My app's Fragment sets up the MapView via the following:
@Override public View
onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.map_panel, container, false);
mapView = (MapView) view.findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
configureMap(mapView.getMap());
return view;
}
private void
configureMap(GoogleMap map, double lat, double lon)
{
if (map == null)
return; // Google Maps not available
try {
MapsInitializer.initialize(getActivity());
}
catch (GooglePlayServicesNotAvailableException e) {
Log.e(LOG_TAG, "Have GoogleMap but then error", e);
return;
}
map.setMyLocationEnabled(true);
LatLng latLng = new LatLng(lat, lon);
CameraUpdate camera = CameraUpdateFactory.newLatLng(latLng);
map.animateCamera(camera);
}
Before I added the call to MapsInitializer, I would get an exception from CameraUpdateFactory. After adding the call, CameraUpdateFactory always succeeds.