我有一个 fragmentActivity,我在其中构建了一个 tabHost,并且在每个选项卡中都有一个 Fragment。好吧,当我选择一个选项卡并传递给其他所有内容时,我有四个选项卡,3 个带有信息,1 个带有一个片段,其中包含一个 google-map-v2(是片段中的一个片段映射,因为我想添加按钮等)进展顺利,但是当我选择地图选项卡时,在另一个选项卡和地图选项卡之后会抛出错误。
我的看法是这样的:
|__||__|__|__|
| __________ |
|| FRAGMENT ||
||_____ _ ||
|| FRAG| |_|||
|| MAP | ||
|| | ||
||_____| ||
||__________||
错误:
01-29 08:32:56.979: E/AndroidRuntime(27738): FATAL EXCEPTION: main
01-29 08:32:56.979: E/AndroidRuntime(27738): android.view.InflateException: Binary XML file line #11: Error inflating class fragment
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.monumentos.vistasmovil.MonumentoMapa.onCreateView(MonumentoMapa.java:127)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1264)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.monumentos.vistasmovil.Monumento.onTabChanged(Monumento.java:279)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:436)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabHost.setCurrentTab(TabHost.java:421)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:158)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:459)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.View.performClick(View.java:2552)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.View$PerformClick.run(View.java:9229)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.os.Handler.handleCallback(Handler.java:587)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.os.Looper.loop(Looper.java:138)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.app.ActivityThread.main(ActivityThread.java:3701)
01-29 08:32:56.979: E/AndroidRuntime(27738): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 08:32:56.979: E/AndroidRuntime(27738): at java.lang.reflect.Method.invoke(Method.java:507)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
01-29 08:32:56.979: E/AndroidRuntime(27738): at dalvik.system.NativeStart.main(Native Method)
01-29 08:32:56.979: E/AndroidRuntime(27738): Caused by: java.lang.IllegalArgumentException: Binary XML file line #11: Duplicate id 0x7f06005c, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-29 08:32:56.979: E/AndroidRuntime(27738): ... 27 more
错误说:
01-29 08:32:56.979: E/AndroidRuntime(27738): Caused by: java.lang.IllegalArgumentException: Binary XML file line #11: Duplicate id 0x7f06005c, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-29 08:32:56.979: E/AndroidRuntime(27738): ... 27 more
这是问题所在,但我不知道为什么只有这个片段有问题:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.monumenos_view_preview, container, false);
return view;
}