google maps are returning null pointer exception

后端 未结 3 1847
孤城傲影
孤城傲影 2021-01-29 02:09

when I am trying to show the maps on my fragment it is returning null pointer exception. I have added everything to the manifest each and every permission. I am attaching the f

3条回答
  •  长情又很酷
    2021-01-29 02:52

    You have to wait until map getting loaded....

    public class ChatFragment extends Fragment implements OnMapReadyCallback {
    
        private void initilizeMap() {
          //SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.map);
    
          SupportMapFragment mapFrag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
          mapFrag.getMapAsync(this);
        }
    
        @Override
        public void onMapReady(final GoogleMap map) {
            googleMap = map;
            //Do other stuff..........
        }
    
    }
    

    Edit

    SupportMapFragment mapFrag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
    

    Check the edit code, use ChildFragmentManager.

提交回复
热议问题