Application crashes when trying to show a few fragments-Collection of common programming errors

Im trying to make a menu that will control the fragments – the screens. (just like in instagram),

But it crashes:

The code of the main activity:

public class All extends Activity {

    Button map;
    Button add;

    View MapFragment;
    View AddFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all);

        map=(Button)findViewById(R.id.map);
        add=(Button)findViewById(R.id.add);

        MapFragment=(View)findViewById(R.id.MapFragment);
        AddFragment=(View)findViewById(R.id.AddFragment);

        MapFragment.bringToFront();

        map.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                MapFragment.bringToFront();
            }
        });

        add.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                AddFragment.bringToFront();
            }
        });
    }

And the logcat:

09-29 19:14:11.765: E/ActivityThread(26360): Failed to inflate
09-29 19:14:11.765: E/ActivityThread(26360): android.view.InflateException: Binary XML file line #255: Error inflating class fragment
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-29 19:14:11.765: E/ActivityThread(26360):    at com.example.free.Add.onCreateView(Add.java:143)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.Activity.onCreateView(Activity.java:4664)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-29 19:14:11.765: E/ActivityThread(26360):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:275)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.Activity.setContentView(Activity.java:1867)
09-29 19:14:11.765: E/ActivityThread(26360):    at com.example.free.All.onCreate(All.java:26)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.Activity.performCreate(Activity.java:5008)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.ActivityThread.access$600(ActivityThread.java:142)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.os.Looper.loop(Looper.java:137)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.ActivityThread.main(ActivityThread.java:4931)
09-29 19:14:11.765: E/ActivityThread(26360):    at java.lang.reflect.Method.invokeNative(Native Method)
09-29 19:14:11.765: E/ActivityThread(26360):    at java.lang.reflect.Method.invoke(Method.java:511)
09-29 19:14:11.765: E/ActivityThread(26360):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-29 19:14:11.765: E/ActivityThread(26360):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
09-29 19:14:11.765: E/ActivityThread(26360):    at dalvik.system.NativeStart.main(Native Method)
09-29 19:14:11.765: E/ActivityThread(26360): Caused by: java.lang.IllegalArgumentException: Binary XML file line #255: Duplicate id 0x7f07001d, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
09-29 19:14:11.765: E/ActivityThread(26360):    at android.app.Activity.onCreateView(Activity.java:4669)
09-29 19:14:11.765: E/ActivityThread(26360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-29 19:14:11.765: E/ActivityThread(26360):    ... 32 more
09-29 19:14:12.480: D/AndroidRuntime(26360): Shutting down VM
09-29 19:14:12.480: W/dalvikvm(26360): threadid=1: thread exiting with uncaught exception (group=0x40ed5300)
09-29 19:14:12.519: E/AndroidRuntime(26360): FATAL EXCEPTION: main
09-29 19:14:12.519: E/AndroidRuntime(26360): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.free/com.example.free.All}: android.view.InflateException: Binary XML file line #255: Error inflating class fragment
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.ActivityThread.access$600(ActivityThread.java:142)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.os.Looper.loop(Looper.java:137)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.ActivityThread.main(ActivityThread.java:4931)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at java.lang.reflect.Method.invokeNative(Native Method)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at java.lang.reflect.Method.invoke(Method.java:511)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at dalvik.system.NativeStart.main(Native Method)
09-29 19:14:12.519: E/AndroidRuntime(26360): Caused by: android.view.InflateException: Binary XML file line #255: Error inflating class fragment
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at com.example.free.Add.onCreateView(Add.java:143)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.Activity.onCreateView(Activity.java:4664)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:275)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.Activity.setContentView(Activity.java:1867)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at com.example.free.All.onCreate(All.java:26)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.Activity.performCreate(Activity.java:5008)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
09-29 19:14:12.519: E/AndroidRuntime(26360):    ... 11 more
09-29 19:14:12.519: E/AndroidRuntime(26360): Caused by: java.lang.IllegalArgumentException: Binary XML file line #255: Duplicate id 0x7f07001d, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.app.Activity.onCreateView(Activity.java:4669)
09-29 19:14:12.519: E/AndroidRuntime(26360):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-29 19:14:12.519: E/AndroidRuntime(26360):    ... 32 more

line 143 on “Add”:

@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            return inflater.inflate(R.layout.activity_add, container, false);
        }

Is there something wrong with it?

The layout:



    

    

    

    

    

    

    


Thanks for your assistance!

Edit

Now Im doing this:

Fragment MapFragment = getSupportFragmentManager().findFragmentById(R.id.MapFragment);