Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app error - Duplicate id 0x7f04000f, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment [duplicate]

I'm trying to make a simple android app and am having trouble fixing this bug.

The app has a 4 tab fixed button navigation and the error occurs when on the 4th tab and switching to another tab. Being on any other page works fine but the 4th tab is causing a fatal error every time. There is nothing on that page except a TextView element. Can anyone help me figure out what's wrong or point me in the right direction?

02-17 21:48:54.378: E/AndroidRuntime(5543): FATAL EXCEPTION: main
02-17 21:48:54.378: E/AndroidRuntime(5543): android.view.InflateException: Binary XML file line #12: Error inflating class fragment
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.example.testthree.MainActivity$MapSectionFragment.onCreateView(MainActivity.java:241)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1264)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:495)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:476)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.example.testthree.MainActivity.onTabSelected(MainActivity.java:95)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:570)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1067)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:489)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.View.performClick(View.java:4084)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.View$PerformClick.run(View.java:16966)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.os.Handler.handleCallback(Handler.java:615)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.os.Looper.loop(Looper.java:137)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.app.ActivityThread.main(ActivityThread.java:4745)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at java.lang.reflect.Method.invokeNative(Native Method)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at java.lang.reflect.Method.invoke(Method.java:511)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at dalvik.system.NativeStart.main(Native Method)
02-17 21:48:54.378: E/AndroidRuntime(5543): Caused by: java.lang.IllegalArgumentException: Binary XML file line #12: Duplicate id 0x7f04000f, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
02-17 21:48:54.378: E/AndroidRuntime(5543):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-17 21:48:54.378: E/AndroidRuntime(5543):     ... 30 more
like image 714
Derek Avatar asked Feb 18 '13 02:02

Derek


2 Answers

Fixed it with the following code in my map fragment:

public void onDestroyView() {
    super.onDestroyView();
    FragmentManager fm = getActivity().getSupportFragmentManager();
    Fragment fragment = (fm.findFragmentById(R.id.map));
    FragmentTransaction ft = fm.beginTransaction();
    ft.remove(fragment);
    ft.commit();
}
like image 136
Derek Avatar answered Sep 27 '22 18:09

Derek


While not an expert in tabs, I would appear to be a problem with the map/map fragment.

Are you including the map more than once across all the tabs?

I would try making sure the id of any added fragments (and map fragments) is unique.

You might also find it useful to remove any fragments that you are not using so as to lessen the chance for conflicts. This is likely to be something similar to removing the fragments that inside the tabs that aren't currently displayed. But like I said, I'm not an expert on tabs.

like image 32
Corey Scott Avatar answered Sep 27 '22 18:09

Corey Scott