Reputation: 4787
I get the following error in my app reported by Google Play:
...
Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
at com.google.android.gms.internal.x.b(Unknown Source)
at com.google.android.gms.maps.CameraUpdateFactory.aE(Unknown Source)
at com.google.android.gms.maps.CameraUpdateFactory.newCameraPosition(Unknown Source)
at com.foo.DetailActivity.onCreate(DetailActivity.java:144)
I've already read posts like this. My code in DetailActivity
(extends FragmentActivity) follows:
try {
MapsInitializer.initialize(this);
} catch (GooglePlayServicesNotAvailableException e) {
Log.e("map", " " + e.getMessage());
}
SharedPreferences settings = getPreferences(0);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(settings.getFloat("lat", -28.709861f), settings.getFloat("lon", 26.015625f)))
.zoom(settings.contains("lat") ? 11 : 6)
.build();
CameraUpdate cu = CameraUpdateFactory.newCameraPosition(cameraPosition); //line 144
I'm not sure how it's still uninitialised. At this point in my code, I haven't created the MapFragment yet. I don't see this would need to be after creating the MapFragment though, since I'm not calling anything from the MapFragment.
Any ideas why this isn't working?
Upvotes: 0
Views: 3727
Reputation: 22232
For the next update replace:
Log.e("map", " " + e.getMessage());
with:
throw new RuntimeException(e);
At least you will get the real reason and not the symptom NPE.
Anyway if Google Play Services are not installed on user's device this code should never try to execute.
There are things like GooglePlayServicesUtil.isGooglePlayServicesAvailable
and other functions which will help you.
Upvotes: 1