java.lang.NullPointerException GoogleMaps V2

后端 未结 4 1845
闹比i
闹比i 2021-01-20 23:40

i just learning about android programming to show map. but when i run this code ,there\'s some error. Can anybody explain why this error occurs? And what I can do to fix this pr

4条回答
  •  走了就别回头了
    2021-01-21 00:10

    In your xml file change this class="com.google.android.gms.maps.MapFragment" to android:name="com.google.android.gms.maps.SupportMapFragment"

    Extend your activity to FragmentActivty and change

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap(); to   
    map= ((SupportMapFragment) getSupportFragmentManager()
                        .findFragmentById(R.id.map)).getMap();
    

    Also check

    if (map== null) 
                {
              map= ((SupportMapFragment) getSupportFragmentManager()
                        .findFragmentById(R.id.map)).getMap();}
    

    Hope this helps.

提交回复
热议问题