title: Android Google Maps V2 in Fragment
body: <p>I am creating an app in android 17 and I am trying to include Google Maps v2. </p>
  
  <p>In my current set-up I have an ActionBar with two tabs, one pointing to travel information and one pointing to Google Maps.</p>
  
  <p>I can get Google maps to display in the main activity, but I can't get the map to display in a fragment.</p>
  
  <p>Here is my Maps Class code:</p>
  
  <pre><code>// Will hold the information for the "Maps" tab
  public class Maps extends FragmentActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          ActionBar actionBar = getActionBar();
          actionBar.setDisplayShowTitleEnabled(false);
          actionBar.setCustomView(R.layout.rowlayout);
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          // Venue Map
  
          LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          RelativeLayout layoutView = (RelativeLayout)inflater.inflate(R.layout.action_bar_tab, null);
          TextView tabText = (TextView) layoutView.findViewById(R.id.tabText);
          ImageView tabImage = (ImageView) layoutView.findViewById(R.id.tabImage);
  
          String venueMapTab = "Travel Information";
          Tab tab = actionBar.newTab();
          TabListener&lt;VenueMap&gt; dayOne = new TabListener&lt;VenueMap&gt;(this,
                  venueMapTab, VenueMap.class);
          tab.setTabListener(dayOne); 
          tabText.setText("Venue Map");
          tab.setCustomView(layoutView);
          actionBar.addTab(tab);
  
          // Google Maps
  
          RelativeLayout layoutViewMaps = (RelativeLayout)inflater.inflate(R.layout.action_bar_tab, null);
          tabText = (TextView) layoutViewMaps.findViewById(R.id.tabText);
          tabImage = (ImageView) layoutViewMaps.findViewById(R.id.tabImage);
  
          String googleMapsTab = "Google Maps";
          tab = actionBar.newTab();
          TabListener&lt;GoogleMaps&gt; dayTwo = new TabListener&lt;GoogleMaps&gt;(this,
                  googleMapsTab, GoogleMaps.class);
          tab.setTabListener(dayTwo);
          tabText.setText("Google Maps");
          tab.setCustomView(layoutViewMaps);
          actionBar.addTab(tab);
  
      }
  </code></pre>
  
  <p>Here is my Google Maps fragment</p>
  
  <pre><code>@Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      getActivity().setContentView(R.layout.google_maps);
  }
  </code></pre>
  
  <p>And the google_maps.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment"/&gt;
  </code></pre>
  
  <p>And my log cat error:</p>
  
  <pre><code>01-28 13:44:09.830: E/AndroidRuntime(22253): FATAL EXCEPTION: main
  01-28 13:44:09.830: E/AndroidRuntime(22253): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zshare.blog/com.zshare.blog.Maps}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.os.Looper.loop(Looper.java:137)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.ActivityThread.main(ActivityThread.java:5039)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at java.lang.reflect.Method.invoke(Method.java:511)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at dalvik.system.NativeStart.main(Native Method)
  01-28 13:44:09.830: E/AndroidRuntime(22253): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Activity.setContentView(Activity.java:1881)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at com.zshare.blog..VenueMap.onActivityCreated(VenueMap.java:32)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Fragment.performActivityCreated(Fragment.java:1703)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Activity.onCreateView(Activity.java:4736)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Activity.setContentView(Activity.java:1881)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at com.zshare.blog.VenueMap.onActivityCreated(VenueMap.java:32)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Fragment.performActivityCreated(Fragment.java:1703)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.BackStackRecord.run(BackStackRecord.java:682)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Activity.performStart(Activity.java:5113)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    ... 11 more
  01-28 13:44:09.830: E/AndroidRuntime(22253): Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f05003b, tag null, or parent id 0x1020002 with another fragment for com.google.android.gms.maps.MapFragment
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.app.Activity.onCreateView(Activity.java:4722)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
  01-28 13:44:09.830: E/AndroidRuntime(22253):    ... 35 more
  </code></pre>
  
  <p>If i display the map in an activity it works, but in a fragment I am getting an error. Any help solving this problem would be appreciated :) </p>