0

I have a slider menu which makes use of fragment class. Whenever, i click on my "Outdoor" tab the Outdoor Fragment class will load perfectly fine. But when i click on the slider menu again on "Outdoor" the Outdoor Fragment crashes.

This is my error

10-09 16:46:17.914: E/Fragment(15011): Fragment not null
10-09 16:46:17.964: E/AndroidRuntime(15011): FATAL EXCEPTION: main
10-09 16:46:17.964: E/AndroidRuntime(15011): Process: me.chihao.maes, PID: 15011
10-09 16:46:17.964: E/AndroidRuntime(15011): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at me.chihao.maes.OutdoorFragment.onCreateView(OutdoorFragment.java:84)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.os.Handler.handleCallback(Handler.java:733)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.os.Handler.dispatchMessage(Handler.java:95)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.os.Looper.loop(Looper.java:212)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.app.ActivityThread.main(ActivityThread.java:5151)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at java.lang.reflect.Method.invokeNative(Native Method)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at java.lang.reflect.Method.invoke(Method.java:515)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at dalvik.system.NativeStart.main(Native Method)
10-09 16:46:17.964: E/AndroidRuntime(15011): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f08003b, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.app.Activity.onCreateView(Activity.java:4791)
10-09 16:46:17.964: E/AndroidRuntime(15011):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
10-09 16:46:17.964: E/AndroidRuntime(15011):    ... 19 more

I am not sure why is this happen as i followed a tutorial online a did it.

This is my outdoor Fragment class :

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_outdoor, container,
            false);

    context = this.getActivity();
     hashmarkers = new HashMap<String, String>();
     hashImages = new HashMap<String, String>();
     refresh = (Button) rootView.findViewById(R.id.refresh);
    try {
        // Loading map
        initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }

    listName.clear();
    listIllness.clear();
    listIC.clear();
    listElderlyimage.clear();
    listArduinomac.clear();
    listLat.clear();
    listLong.clear();
    googleMap.getUiSettings().setZoomGesturesEnabled(true);
    googleMap.getUiSettings().setRotateGesturesEnabled(true);
    googleMap.getUiSettings().setMyLocationButtonEnabled(true);
    googleMap.setMyLocationEnabled(true);
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
            1.3000, 103.8000), 10.0f));
    zone = Act_Main.getzone();
    ip = Act_Main.getip();
    URL_gps_location = "http://" + ip + "/droidlogin/gps_location.php";
    post4 = new Httppostaux();
    googleMap.setInfoWindowAdapter(new InfoWindowAdapterMarker(context));
    googleMap.clear();
    new asyncGPS().execute(zone);

    refresh.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            googleMap.clear();
            // TODO Auto-generated method stub
            listName.clear();
            listIllness.clear();
            listIC.clear();
            listElderlyimage.clear();
            listArduinomac.clear();
            listLat.clear();
            listLong.clear();


            new asyncGPS().execute(zone);
        }
    });
    return rootView;
}

and incase you need to check my fragment_outdoor.xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/refresh" />

<Button
    android:id="@+id/refresh"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:text="Refresh" />

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
EggRollMan
  • 583
  • 1
  • 8
  • 20
  • http://stackoverflow.com/questions/14565460/error-opening-supportmapfragment-for-second-time Check Kaleb answer – momo Oct 09 '14 at 08:56
  • Take a look at [how to use maps inside the fragment](http://stackoverflow.com/questions/25848513/how-to-use-maps-inside-the-fragment/25848811#25848811) – Kaushik Oct 09 '14 at 09:04
  • add support map fragment class="com.google.android.gms.maps.SupportMapFragment" – williamj949 Oct 09 '14 at 09:05

1 Answers1

0

You need to show all the code, especially that one that switches your tabs. But error you receive:

Duplicate id 0x7f08003b, tag null, or parent id 0xffffffff with another fragment
for com.google.android.gms.maps.MapFragment

indicates that you try to add view with this fragment to the root view that already contains it, hence conflict of id. You may want alternatively to initiate and add your map fragment from code directly, instead of having it referenced in XML code.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • hi there, im still not sure why is this happening . What i did was Open slider menu -> press on Outdoor tab -> the google map loads perfectly fine. When i open slider menu again -> press on Outdoor tab-> my application crashes immediately. – EggRollMan Oct 09 '14 at 09:13
  • I told you already - show the right code that swaps things. Show the whole layout not just fragment, because your issue is outside of your map fragment – Marcin Orlowski Oct 09 '14 at 10:10