title: How to fix the android.view.InflateException: Error inflating class fragment when using google maps v2 fragment
body: <p>I am using google map v2 fragment as a tab's content of a tabhost. The first time I get the map as it should be appeared, but when I navigate with tabs and I want to return back to the tab where the map exists I get this error:</p>
  
  <pre><code>04-19 00:02:08.623: E/AndroidRuntime(5163): android.view.InflateException: Binary XML file line #10: Error inflating class fragment
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at com.example.appv1.MapFragment.onCreateView(MapFragment.java:34)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1297)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.os.Handler.handleCallback(Handler.java:725)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.os.Handler.dispatchMessage(Handler.java:92)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.os.Looper.loop(Looper.java:137)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.app.ActivityThread.main(ActivityThread.java:5041)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at java.lang.reflect.Method.invokeNative(Native Method)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at java.lang.reflect.Method.invoke(Method.java:511)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at dalvik.system.NativeStart.main(Native Method)
  04-19 00:02:08.623: E/AndroidRuntime(5163): Caused by: java.lang.IllegalArgumentException: Binary XML file line #10: Duplicate id 0x7f0a0083, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
  04-19 00:02:08.623: E/AndroidRuntime(5163):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
  </code></pre>
  
  <p>Here's my fragment.JAVA:</p>
  
  <pre><code>public class MapFragment extends Fragment {
  
  private GoogleMap map;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.activity_tab_map, container, false);
  
      map = ((SupportMapFragment) getFragmentManager()
              .findFragmentById(R.id.tabmap)).getMap();
      map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
  
      return rootView;
  }
  </code></pre>
  
  <p>And here's my layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  &gt;
  
  &lt;fragment 
      android:id="@+id/tabmap"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_alignParentTop="true"
      android:layout_alignParentBottom="true"
      android:name="com.google.android.gms.maps.SupportMapFragment"/&gt; 
  
  &lt;Button
  android:id="@+id/btn_tabmapyaller"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginLeft="250dp"
  android:text="Y aller" /&gt; 
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>edit (Solved)</strong>: Finally, I've found the solution. The method onDestroyView() should be added as below in the JAVA file MapFragment:</p>
  
  <pre><code>@Override
  public void onDestroyView() {
      super.onDestroyView();
      SupportMapFragment f = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.tabmap);
      if (f != null &amp;&amp; f.isResumed()){
          getFragmentManager().beginTransaction().remove(f).commit();
      }
  }
  </code></pre>