2013-02-18 39 views
6

我試圖製作一個簡單的android應用程序,並且無法修復此錯誤。Android應用程序錯誤 - 重複編號0x7f04000f,標記爲空或父編號0x0與com.google.android.gms.maps.SupportMapFragment的另一個片段

該應用程序有一個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 

回答

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

謝謝你今天救了我:),但什麼問題你能解釋一下請+1 – 2014-03-28 09:39:47

+1

哇,謝謝!爲我節省了很多時間和頭痛... – Woody 2014-06-19 13:48:59

+1

@Derek,謝謝你的回答,它幫助我修復了崩潰。有趣的是,在我幾天前將appcompat-v7支持庫更新到版本21(帶有材質設計)之後,原來的錯誤消失了,並且不需要重寫onDestroyView()。看起來這個崩潰是由舊版支持庫中的一個錯誤引起的,谷歌已經在v21中修復了它。 – 2014-11-14 20:30:10

2

儘管標籤不是專家,我似乎是與地圖/地圖片段的問題。

您是否在所有選項卡中多次包含地圖?

我會嘗試確保任何添加的片段(和地圖片段)的ID是唯一的。

您可能還會發現刪除未使用的任何碎片以減少衝突的可能性很有用。這很可能與刪除當前未顯示的選項卡內的片段類似。但就像我說的,我不是製表符的專家。

相關問題