首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >空对象引用android上的“'int java.util.List.size()”

空对象引用android上的“'int java.util.List.size()”
EN

Stack Overflow用户
提问于 2018-07-24 07:31:22
回答 1查看 548关注 0票数 -2

我正在创建一个在地图上显示标记的应用程序。问题是,当我运行我的应用程序时,我得到了以下错误:

代码语言:javascript
运行
复制
 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扩展了片段{

代码语言:javascript
运行
复制
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;
}

这是我的数据库屏幕:

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51488475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档