NullPointerException:尝试调用虚方法' void com.google.android.gms.maps.MapFragment.getMapAsync

时间:2017-07-02 03:15:13

标签: java android google-maps nullpointerexception mapfragment

我正在使用com.google.android.gms:play-services-maps:11.0.2版Google地图服务。尝试调用以下内容时,出现以下错误:

  

java.lang.NullPointerException:尝试调用虚方法
  空隙

com.google.android.gms.maps.MapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)'在空对象引用上

以下是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

}

1 个答案:

答案 0 :(得分:0)

您似乎正在使用Promise.all(deletePromises) .then(res1 => { console.log("Print res1:", res1); arr.menuItems.forEach((item, idx) => { if (!isEmpty(item.new_filename)) { uploadPromises.push(uploadToFirebase(user.uid, item)); } }); return Promise.all(uploadPromises); }) .then(res2 => { console.log("Print res2:", res2); dispatch({ type: MENU_UPDATE_SUCCESS, payload: arr }); dispatch(reset("menuItem")); }) .catch(error => { console.log("Print error:", error); }); 而不是SupportMapFragment

更改此行:

MapFragment

对此:

mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);