6

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

该应用程序具有 4 个选项卡固定按钮导航,并且在第 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
4

2 回答 2

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();
}
于 2013-02-18T03:45:24.030 回答
2

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

您是否在所有选项卡中多次包含地图?

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

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

于 2013-02-18T03:34:55.000 回答