SupportMapFragment不工作,给出错误

时间:2014-09-20 15:36:00

标签: android google-maps

当我第一次打开应用程序时,它会正确显示地图。但是当我第二次打开应用程序时,它总是崩溃。

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    FragmentManager fm = getChildFragmentManager();
    supportMapFragment = (SupportMapFragment)fm.findFragmentById(R.id.doctordetail_map);

}

2 个答案:

答案 0 :(得分:1)

使用此代码,我也面临这个问题,这将对您有所帮助。

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    FragmentManager fm = getChildFragmentManager();
    supportMapFragment = (SupportMapFragment)fm.findFragmentById(R.id.doctordetail_map);
    if (supportMapFragment == null) {
        supportMapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.doctordetail_map, supportMapFragment).commit();
    }

}

答案 1 :(得分:0)

问题是由于重复ID

在ondestory中销毁地图