Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android片段Google Maps V2:膨胀类时出错_Android_Android Fragments - Fatal编程技术网

Android片段Google Maps V2:膨胀类时出错

Android片段Google Maps V2:膨胀类时出错,android,android-fragments,Android,Android Fragments,我正在开发一个使用fragment选项卡的应用程序,我的一个fragment使用Google Maps V2 SupportMapFragment 我的xml: <RelativeLayout android:id="@+id/map_container" android:layout_width="fill_parent" android:layout_height="fill_parent"> <fragment android:id="

我正在开发一个使用fragment选项卡的应用程序,我的一个fragment使用Google Maps V2 SupportMapFragment

我的xml:

<RelativeLayout
   android:id="@+id/map_container"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   <fragment
     android:id="@+id/map"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     class="com.google.android.gms.maps.SupportMapFragment" 
   />
</RelativeLayout>
我从这里调用B Fragment A->B,当我从B->返回时,一个片段onCreateView抛出一个异常,android.view.InflateException:Binary XML文件第132行:创建映射片段后,当再次返回到该片段时,错误膨胀类片段

,调用片段为onCreateView,这就是为什么要强制关闭

在包含地图的片段中尝试一次

@Override
public void onDestroyView() {
    super.onDestroyView();

    Fragment f = getFragmentManager().findFragmentById(R.id.map);
    if (f != null) 
        getFragmentManager().beginTransaction().remove(f).commit();
}

请评论我的结果

检查我的答案,所以在这个链接上:嘿,纳雷什·雷迪,谢谢你回答我的问题。。。因为我使用的是片段选项卡,所以我使用一个基本容器来处理选项卡中的视图层次结构,您的代码不起作用,但我使用getFragmentManager来处理getFragmentManager,然后它就像一个符咒一样工作。。。
public void onDestroyView() {
    super.onDestroyView();
    Log.d(TAG, "onDestroyView");

    Fragment f = getActivity()
            .getSupportFragmentManager().findFragmentById(R.id.map);
    if (f != null) {
        getActivity().getSupportFragmentManager()
        .beginTransaction().remove(f).commit();
    }
}
public void onDestroyView() {
    super.onDestroyView();
    Log.d(TAG, "onDestroyView");

    Fragment f = getActivity()
            .getSupportFragmentManager().findFragmentById(R.id.map);
    if (f != null) {
        getActivity().getSupportFragmentManager()
        .beginTransaction().remove(f).commit();
    }
}