为什么谷歌地图v2突然被java.lang.NullPointer崩溃:尝试获取空数组的长度?
我有一个由NullPointerException引起的问题。应用程序今天开始崩溃,当我试图做mMapView.onCreate(savedInstanceState);但昨天还好。我只是将我的布局文件更改为具有其他名称的另一个(类似)文件。以下是例外情况:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.parking.android, PID: 17585 java.lang.NullPointerException: 尝试获取映射处空数组的长度。G.a.a(未知来源)在地图上。V.N.A(未知来源)在地图上。D.e.a(未知来源)在地图上。D.p.a(未知来源) at maps.ad.ae.a(未知来源) at maps.ad.t.a(未知来源) at maps.ad.R.a(未知来源) at uo.onTransact(:com.google.android.gms.DynamiteModulesB:66) at android.os.Binder.transact(Binder.java:385) at com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.onCreate(Unknown Source) at com.google.android.gms.maps.MapView$zza.onCreate(Unknown Source) at com.google.android.gms.dynamic.zza$3.zzb(Unknown Source) atcom.google.android.gms.dynamic.zza$1.zza(Unknown Source) at com.google.android.gms.maps.MapView$zzb.zzbow(Unknown Source) at com.google.android.gms.maps.MapView$zzb.zza(Unknown Source) at com.google.android.gms.dynamic.zza.zza(Unknown Source) at com.google.android.gms.dynamic.zza.onCreate(Unknown Source) at com.google.android.gms.maps.MapView.onCreate(Unknown Source) at com.parking.android.map.fragment.MapsFragment.initMap(MapsFragment.java:105) atcom.parking.android.map.fragment.MapsFragment.onCreateView(MapsFragment.java:92) at com.parking.android.base_arch.fragment.BaseFragment.onCreateView(BaseFragment.java:48) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517) at android.os.Handler.handleCallback(Handler.java:815) at android.os.handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5550) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Native Method)java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
以下是我使用mapView的一些代码:
@Override
protected void onCreateView(Bundle savedInstanceState) {
super.onCreateView(savedInstanceState);
initMap(savedInstanceState);
}
private void initMap(Bundle savedInstanceState) {
mMapView.onCreate(savedInstanceState);
mMapView.onResume();
try {
MapsInitializer.initialize(getActContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getExtendedMapAsync(this);
locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
try {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 400, 1000, this);
} catch (SecurityException e) {
Log.e(TAG, "onLocationChanged: ", e);
}
}
@Override
public void onPause() {
mMapView.onPause();
super.onPause();
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onDestroy() {
mMapView.onDestroy();
super.onDestroy();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
presenter.getParkings();
mMap.setOnMarkerClickListener(this);
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
}
@Override
public void onLocationChanged(Location location) {
if (mMap == null)
return;
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 14);
mMap.animateCamera(cameraUpdate);
try {
locationManager.removeUpdates(this);
} catch (SecurityException e) {
Log.e(TAG, "onLocationChanged: ", e);
}
}