Binary XML file line #10: Error inflating class fragment

后端 未结 2 1082
一向
一向 2021-01-27 13:53

In my project I use three tab to show three activities in single screen. Tab 1 - Map
Tab 2 - Games
Tab 3 - Imageflipper
When I select tabs in series like Map--->Ga

2条回答
  •  离开以前
    2021-01-27 14:22

    Caused by: java.lang.IllegalArgumentException: Binary XML file line #10: Duplicate id 0x7f050010, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
    

    you are absolutely right about the error bieng the xml, but only because you are creating a new fragment that android is already holding on the stack.

    instead of creating a new fragemtn you want to use a FragmentManager

    FragmentManager fman=getFragmentManager();
    
    fman.popBackStack();
    

    itll be something along these lines.... for more exact code....

    Fragment fragment = (Fragment) getFragmentManager().
                        .findFragmentById(R.your id here);
                    if (fragment != null && fragment.isInLayout()) {
    
                      fman.beginTransaction().show(fragment)
                    } else {
                      Fragment fragment = (Fragment) getFragmentManager().beginTransaction().add(your container-the file the error is coming from that holds all you fragments, fragment)
                          fman.beginTransaction().show(fragment)
    
                    }
    

提交回复
热议问题