Android应用程序错误 - 使用com.google.android.gms.maps.SupportMapFragment的另一个片段重复ID 0x7f04000f,标记为null或父ID为0x0

时间:2013-02-18 02:58:09

标签: android android-layout

我正在尝试创建一个简单的Android应用程序,但我无法修复此错误。

该应用程序有一个4选项卡固定按钮导航,在第4个选项卡上切换到另一个选项卡时发生错误。在任何其他页面上工作正常,但第四个选项卡每次都会导致致命错误。除了TextView元素之外,该页面上没有任何内容。任何人都可以帮我弄清楚什么是错的或指出我正确的方向?

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

2 个答案:

答案 0 :(得分:44)

使用我的地图片段中的以下代码修复了它:

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();
}

答案 1 :(得分:2)

虽然不是标签专家,但我似乎是地图/地图片段的问题。

您是否在所有标签中多次包含地图?

我会尝试确保任何添加的片段(和地图片段)的ID都是唯一的。

您可能还发现删除任何未使用的片段非常有用,以减少发生冲突的可能性。这可能类似于删除当前未显示的选项卡内的片段。但就像我说的那样,我不是标签专家。