title: android.view.InflateException: Binary XML file line: Error inflating class fragment
body: <p>I'm trying to make an app that contains an ActionBar with 3 tabs: "Map", "Destinatiosn" and "About Us".  Basically i'm using ViewPager as main layout and for individual pager views i use Fragments.</p>
  
  <ul>
  <li><p>activity_main.xml</p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/pager"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre></li>
  <li><p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements ActionBar.TabListener {   
  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  // Tab titles
  private String[] tabs = { "Maps", "Destinations", "About us" };
  
  /***************************************************************************************
   * 
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      // Initialization
      //tabs = getResources().getStringArray(R.array.tabs_titles);
      viewPager = (ViewPager) findViewById(R.id.pager);
      actionBar = getActionBar();
      mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
  
      viewPager.setAdapter(mAdapter);
      //actionBar.setHomeButtonEnabled(false);
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
  
      // Adding Tabs
      for (String tab_name : tabs) {
          actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
      }
  
      /**
       * on swiping the viewpager make respective tab selected
       * */
      viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
          @Override
          public void onPageSelected(int position) {
              // on changing the page
              // make respected tab selected
              actionBar.setSelectedNavigationItem(position);
          }
  
          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {
          }
  
          @Override
          public void onPageScrollStateChanged(int arg0) {
          }
      });
  }
  
  /***************************************************************************************
   * 
   */
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  /***************************************************************************************
   * 
   */
  @Override
  public void onTabReselected(Tab tab, android.app.FragmentTransaction arg1) {
  
  
  }
  
  /***************************************************************************************
   * 
   */
  @Override
  public void onTabSelected(Tab tab, android.app.FragmentTransaction arg1) {
      // on tab selected
      // show respected fragment view
      viewPager.setCurrentItem(tab.getPosition());
  
  }
  
  /***************************************************************************************
   * 
   */
  @Override
  public void onTabUnselected(Tab tab, android.app.FragmentTransaction arg1) {
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>}</p></li>
  </ul>
  
  <p>I am creating a FragmentPagerAdapter class to provide views to tab fragments. </p>
  
  <pre><code>public class TabsPagerAdapter extends FragmentPagerAdapter {
  
  public TabsPagerAdapter(FragmentManager fm) {
      super(fm);
  }
  
  @Override
  public Fragment getItem(int index) {
      switch (index) {
      case 0:
          // Map fragment activity
          return new MapFragment();
      case 1:
          // Destinations fragment activity
          return new DestinationsFragment();
      case 2:
          // About Us fragment activity
          return new AboutUsFragment();
      }
  
      return null;
  }
  
  @Override
  public int getCount() {
      // get item count - equal to number of tabs
      return 3;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Every one of the items have a layout file with his activity class. </p>
  
  <ol>
  <li><p>Map </p>
  
  <ul>
  <li><p>fragment_map Layout</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  &lt;fragment
      android:id="@+id/map"
      android:name="com.google.android.gms.maps.SupportMapFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre></li>
  <li><p>MapFragment class</p>
  
  <pre><code>public class MapFragment extends Fragment {
  GoogleMap mapa;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    
  
  try{
      if(mapa == null){
          mapa = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap(); 
      }             
      View rootView = inflater.inflate(R.layout.fragment_map, container, false);          
      return rootView;
  }catch(Exception e){
      View rootView = inflater.inflate(R.layout.fragment_map, container, false);
  
      e.printStackTrace();
      return rootView;
  }
  </code></pre>
  
  <p>}
  }</p></li>
  <li><p>Destinations (just a Relative Layout with a Text view for now)</p></li>
  </ul></li>
  </ol>
  
  <p>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"
          android:orientation="vertical"
          android:background="#ff8400" &gt;
  
              &lt;TextView 
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:text="Destinations Screen"
                  android:textSize="20sp"
                  android:layout_centerInParent="true"/&gt;
          &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>class</p>
  
  <pre><code>public class DestinationsFragment extends Fragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
  
          Log.d("", "CESAR");
          View rootView = inflater.inflate(R.layout.fragment_destinations, container, false);
  
          return rootView;
      }
  }
  </code></pre>
  
  <ul>
  <li>About Us (just a Relative Layout with a Text view for now)</li>
  </ul>
  
  <p>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"
              android:orientation="vertical"
              android:background="#17df0d"&gt;
  
          &lt;TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:text="Diseñar la pantalla de About Us"
              android:textSize="20sp"
              android:layout_centerInParent="true"/&gt;
  
          &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>class</p>
  
  <pre><code>        public class AboutUsFragment extends Fragment {
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_about_us, container, false);
  
          return rootView;
       }
       }
  </code></pre>
  
  <p>The problem is that when I change from tab "About Us" to any other tab, the app stops working and crashes. But this doesn't happen when i change from tab "Destinations" to the tab of "Map" and backwards. This error came when I added the MapFragment, before that, the map layout was just a RelativeLayout with a text view and worked well. The Map works.</p>
  
  <ul>
  <li><p>Excption stacktrace</p>
  
  <pre><code>04-10 00:35:23.070: W/System.err(16428): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
  04-10 00:35:23.070: W/System.err(16428):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
  04-10 00:35:23.070: W/System.err(16428):    at android.view.LayoutInflater.rInflate(LayoutInflater.java)
  04-10 00:35:23.070: W/System.err(16428):    at android.view.LayoutInflater.inflate(LayoutInflater.java)
  04-10 00:35:23.075: W/System.err(16428):    at android.view.LayoutInflater.inflate(LayoutInflater.java)
  04-10 00:35:23.075: W/System.err(16428):    at com.bikes.touristtest.MapaFragment.onCreateView(MapaFragment.java:22)
  04-10 00:35:23.075: W/System.err(16428):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
  04-10 00:35:23.075: W/System.err(16428):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
  04-10 00:35:23.075: W/System.err(16428):    at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1291)
  04-10 00:35:23.080: W/System.err(16428):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
  04-10 00:35:23.080: W/System.err(16428):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
  04-10 00:35:23.080: W/System.err(16428):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
  04-10 00:35:23.080: W/System.err(16428):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
  04-10 00:35:23.080: W/System.err(16428):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
  04-10 00:35:23.085: W/System.err(16428):    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:550)
  04-10 00:35:23.085: W/System.err(16428):    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:509)
  04-10 00:35:23.085: W/System.err(16428):    at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:490)
  04-10 00:35:23.085: W/System.err(16428):    at com.bikes.touristtest.MainActivity.onTabSelected(MainActivity.java:92)
  04-10 00:35:23.090: W/System.err(16428):    at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java)
  04-10 00:35:23.090: W/System.err(16428):    at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java)
  04-10 00:35:23.090: W/System.err(16428):    at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java)
  04-10 00:35:23.090: W/System.err(16428):    at android.view.View.performClick(View.java)
  04-10 00:35:23.090: W/System.err(16428):    at android.view.View$PerformClick.run(View.java)
  04-10 00:35:23.090: W/System.err(16428):    at android.os.Handler.handleCallback(Handler.java)
  04-10 00:35:23.095: W/System.err(16428):    at android.os.Handler.dispatchMessage(Handler.java)
  04-10 00:35:23.095: W/System.err(16428):    at android.os.Looper.loop(Looper.java)
  04-10 00:35:23.095: W/System.err(16428):    at android.app.ActivityThread.main(ActivityThread.java)
  04-10 00:35:23.095: W/System.err(16428):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-10 00:35:23.095: W/System.err(16428):    at java.lang.reflect.Method.invoke(Method.java:511)
  04-10 00:35:23.095: W/System.err(16428):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
  04-10 00:35:23.100: W/System.err(16428):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
  04-10 00:35:23.100: W/System.err(16428):    at dalvik.system.NativeStart.main(Native Method)
  04-10 00:35:23.100: W/System.err(16428): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f050040, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
  04-10 00:35:23.105: W/System.err(16428):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
  04-10 00:35:23.105: W/System.err(16428):    ... 31 more
  </code></pre></li>
  </ul>