MapView onCreate throws NullPointerException on LG devices

前端 未结 1 1958
礼貌的吻别
礼貌的吻别 2021-02-09 00:42

First of all, this problem is for me only reproducible on LG devices (LG G4 and G5) running Android 6. The problem was introduced through the last update of the google play serv

1条回答
  •  孤城傲影
    2021-02-09 01:10

    You can try to use MapFragment instead of MapView because for updated google play services 11.0.55 not supporting MapView. I used MapView its worked for me.

    Activity class:

        private SupportMapFragment mMapFragment; 
    
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            //return inflater.inflate(R.layout.fragment_find_direction, container, false);
            View view = inflater.inflate(R.layout.fragment_find_direction, null, false);
            SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                    .findFragmentById(R.id.map_fragment);
            mMapFragment.getMapAsync(this);
            mMapFragment = mapFragment;
            return view;
        }
    
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    mMapFragment.onCreate(savedInstanceState);
    }
    

    Xml class:

    
    
    

    0 讨论(0)
提交回复
热议问题