我正在创建一个在地图上显示标记的应用程序。问题是,当我运行我的应用程序时,我得到了以下错误:
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
at com.flag.app.app.fragment.FragmentMap$1.onMapReady(FragmentMap.java:186)
at com.google.android.gms.maps.zzac.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzaq.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)这是我的FragmentMap.class
公共类FragmentMap扩展了片段{
private GoogleMap googleMap;
public MapView mMapView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
mMapView = rootView.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(new OnMapReadyCallback() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
Log.d("debug", "map ready called");
LatLng lviv = new LatLng(49.838, 24.029);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(lviv, 12));
if (ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.d("debug", "problem");
}
List<Marker> markerList = getActivity().getIntent().getParcelableArrayListExtra(EXTRA_MARKER_LIST);
for (int i = 0; i < markerList.size(); i++) {
Marker marker = markerList.get(i);
Location location = marker.getLocation();
clusterManager.setItems(markerList);
}
}
});
return rootView;
}这是我的数据库屏幕:

https://stackoverflow.com/questions/51488475
复制相似问题