我将从Detail Activity中获取数据,因此我正在更新Map on onResume,并且它在animateCamera方法上崩溃。我尝试了所有可用的解决方案。请看以下代码:java.lang.NullPointerException:CameraUpdateFactory未初始化,调用方法on“onResume”
异常:显示java.lang.NullPointerException:CameraUpdateFactory未初始化
private void zoomToShowAllMarkers(final GoogleMap map) {
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (MapLocations marker : arrMarkers) {
final LatLng pos = new LatLng(marker.getLatitude(),marker.getLongitude());
builder.include(pos);
map.addMarker(new MarkerOptions().position(pos));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(pos, 17.0f));
}
}
public void onResume() {
super.onResume();
if(mapView!=null && mapView.isShown())
mapView.onResume();
zoomToShowAllMarkers(map);
}
我在下面因错误代码中删除GooglePlayServicesNotAvailableException catch子句“无法到达catch块的GooglePlayServicesNotAvailableException。这个异常是永远不会从try语句的身体扔”。 – 2014-11-04 08:04:34
尝试{ \t \t \t \t MapsInitializer.initialize(this.getActivity()); \t \t \t}赶上(GooglePlayServicesNotAvailableException E){ \t \t \t \t e.printStackTrace(); \t \t \t} – 2014-11-04 08:05:12