title: App crashing when using fragments
body: <p>Im working with fragments and..</p>
  
  <p>Ive got a problem in my code that I just cant find.</p>
  
  <p>The logcat points at this piece of code, in one of my fragments:</p>
  
  <pre><code>    @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      return inflater.inflate(R.layout.activity_main, container, false);
  }
  </code></pre>
  
  <p>My main class (the FragmentActivity):</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentTransaction;
  import android.view.View;
  
  public class Fragments extends FragmentActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_fragments);
  
          MainActivity fragment = new MainActivity();
          FragmentTransaction transaction = getSupportFragmentManager()
                  .beginTransaction();
          transaction.add(R.id.fragment_place, fragment);
          transaction.commit();
      }
  
      public void onSelectFragment(View view) {
  
          Fragment newFragment;
  
          if (view == findViewById(R.id.add)) {
              newFragment = new Add();
          } else if (view == findViewById(R.id.map)) {
              newFragment = new MainActivity();
          } else {
              newFragment = new MainActivity();
          }
  
          FragmentTransaction transaction = getSupportFragmentManager()
                  .beginTransaction();
          transaction.replace(R.id.fragment_place, newFragment);
          transaction.addToBackStack(null);
          transaction.commit();
      }
  
  }
  </code></pre>
  
  <p>and the logcat:</p>
  
  <pre><code>09-30 00:02:52.363: E/AndroidRuntime(32284): FATAL EXCEPTION: main
  09-30 00:02:52.363: E/AndroidRuntime(32284): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.free/com.example.free.Fragments}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.ActivityThread.access$600(ActivityThread.java:142)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.os.Handler.dispatchMessage(Handler.java:99)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.os.Looper.loop(Looper.java:137)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.ActivityThread.main(ActivityThread.java:4931)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at java.lang.reflect.Method.invokeNative(Native Method)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at java.lang.reflect.Method.invoke(Method.java:511)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at dalvik.system.NativeStart.main(Native Method)
  09-30 00:02:52.363: E/AndroidRuntime(32284): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at com.example.free.MainActivity.onCreateView(MainActivity.java:124)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:556)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.Activity.performStart(Activity.java:5018)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    ... 11 more
  09-30 00:02:52.363: E/AndroidRuntime(32284): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
  09-30 00:02:52.363: E/AndroidRuntime(32284):    ... 24 more
  </code></pre>
  
  <p>The class "MainActivity" is very long so I pasted it using pasebin:</p>
  
  <p><a href="http://pastebin.com/Lt3wbNzD" rel="nofollow">http://pastebin.com/Lt3wbNzD</a></p>
  
  <p>Thanks for your assistance!</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>private GoogleMap map;
  
  FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
          transaction.add(R.id.map, map).commit();
  </code></pre>
  
  <p>it shows an error:</p>
  
  <blockquote>
    <p>The method add(int, Fragment) in the type FragmentTransaction is not
    applicable for the arguments (int, GoogleMap)</p>
  </blockquote>