0
我一直在試圖設置一個地圖使用一些幫助,我到了這裏。所以,這是非常簡單的代碼,但崩潰。我究竟做錯了什麼?getMapAysnc(this)崩潰與空指針異常
公共類ShowDirection擴展FragmentActivity實現OnMapReadyCallback {
private GoogleMap myMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_directions);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this); // causes the Exception
}
@Override
public void onMapReady(final GoogleMap map) {
this.myMap = map;
myMap.setMyLocationEnabled(true);
}
嘗試將'this'更改爲'ShowDirection.this'並且發佈您的logcat請問 –
您是否擁有id = map的片段?它導致錯誤原因mapFragment是'null' – Vucko
@KISHORE_ZE應該沒有任何區別。 – Raghunandan