Google Maps Fragment returning null inside a fragment

前端 未结 8 889
花落未央
花落未央 2020-11-27 18:05

So I have an empty fragment that contains a map fragment. Whenever I try to activate the fragment containing the map, my app crashes and returns a null pointer error on this

8条回答
  •  难免孤独
    2020-11-27 18:43

    I have solved the issue. this line when I have a viewpager:

    mMap = ((SupportMapFragment) MainActivity.fragmentManager
                    .findFragmentById(R.id.mapView)).getMap();
    

    you have to change to this:

      mMap = ((SupportMapFragment) getChildFragmentManager()
                .findFragmentById(R.id.mapView)).getMap();
    

提交回复
热议问题