我发现了很多与此相关的问题,但仍然无法超越我的问题。 android.view.InflateException: Binary XML file line #91: Error inflating class fragment
我的问题是,#91 的情况有所不同吗?因为没有人问过这个问题(虽然其他问题有#20,#2,#11 )。或者这就像在.java中指示行号一样?如果我需要提供更多细节,请告诉我。
P.S。:我在浏览ViewPager的页面时遇到此错误,但仅在第二轮。 谢谢
我的完整logcat
08-19 07:32:24.080: E/AndroidRuntime(15498): FATAL EXCEPTION: main
08-19 07:32:24.080: E/AndroidRuntime(15498): android.view.InflateException: Binary XML file line #91: Error inflating class fragment
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-19 07:32:24.080: E/AndroidRuntime(15498): at com.example.fragments.Recommend.onCreateView(Recommend.java:47)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1291)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.View.measure(View.java:12862)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:704)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.View.measure(View.java:12862)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.View.measure(View.java:12862)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.View.measure(View.java:12862)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
08-19 07:32:24.080: E/AndroidRuntime(15498): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2125)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.View.measure(View.java:12862)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.os.Looper.loop(Looper.java:137)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-19 07:32:24.080: E/AndroidRuntime(15498): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 07:32:24.080: E/AndroidRuntime(15498): at java.lang.reflect.Method.invoke(Method.java:511)
08-19 07:32:24.080: E/AndroidRuntime(15498): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
08-19 07:32:24.080: E/AndroidRuntime(15498): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:573)
08-19 07:32:24.080: E/AndroidRuntime(15498): at dalvik.system.NativeStart.main(Native Method)
08-19 07:32:24.080: E/AndroidRuntime(15498): Caused by: java.lang.IllegalArgumentException: Binary XML file line #91: Duplicate id 0x7f080087, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
08-19 07:32:24.080: E/AndroidRuntime(15498): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
08-19 07:32:24.080: E/AndroidRuntime(15498): ... 37 more
问题:为什么在第一轮翻转片段后出现错误?为什么不是第一个?
答案 0 :(得分:0)
其实我有两个问题。 问题1:
我在2个片段中有相同的地图名称。我把它改成了不同的
问题2:主要问题。
我将此代码添加到我的片段
中@Override
public void onDestroyView() {
super.onDestroyView();
FragmentManager fm = getActivity().getSupportFragmentManager();
Fragment fragment = (fm.findFragmentById(R.id.mapz1));
FragmentTransaction ft = fm.beginTransaction();
ft.remove(fragment);
ft.commit();
}
此代码以编程方式创建地图片段并初始化地图。