mapFragment.getMap() returns null

前端 未结 3 770
醉话见心
醉话见心 2020-12-20 19:40

I\'m trying to get a map from a SupportMapFragment but it returns null. From what I read this could be because the fragment is not yet fully displayed and therefore no map e

3条回答
  •  醉梦人生
    2020-12-20 20:27

    Try moving all code that references your GoogleMap to onStart() or onResume(). The map in a map fragment isn't instantiated until after the fragment has gone through onCreateView (link), which happens after the parent activity has gone through onCreate(). Also, you need to check your GoogleMap for null regardless, because if google play services aren't installed, or the map isn't available for some other reason, it will be null.

提交回复
热议问题