当前位置: 首页 > 知识库问答 >
问题:

Android.view.fillateException:二进制XML文件第33行:inflating类片段时出错

敖淮晨
2023-03-14

我有一点问题,如果我的谷歌地图应用程序。我的应用程序中有三个按钮;“打开谷歌地图”、“摄像头”和“触摸”。当应用程序拉努克时,它会直接进入Google Maps屏幕,在此之前一切都很好,但当用户在Google Maps屏幕上并再次单击Google Maps按钮时,应用程序崩溃,我的logcat中出现以下错误;

02-28 11:39:25.844: E/AndroidRuntime(2782): FATAL EXCEPTION: main
02-28 11:39:25.844: E/AndroidRuntime(2782): Process: com.GoogleMapsapplication.main, PID: 2782
02-28 11:39:25.844: E/AndroidRuntime(2782): android.view.InflateException: Binary XML file line #33: Error inflating class fragment
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at com.augmentedthorpepark.main.FragmentGoogleMap.onCreateView(GoogleMapsFragment.java:50)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.Fragment.performCreateView(Fragment.java:1700)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.BackStackRecord.run(BackStackRecord.java:684)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.os.Handler.handleCallback(Handler.java:733)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.os.Handler.dispatchMessage(Handler.java:95)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.os.Looper.loop(Looper.java:136)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.ActivityThread.main(ActivityThread.java:5146)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at java.lang.reflect.Method.invokeNative(Native Method)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at java.lang.reflect.Method.invoke(Method.java:515)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at dalvik.system.NativeStart.main(Native Method)
02-28 11:39:25.844: E/AndroidRuntime(2782): Caused by: java.lang.IllegalArgumentException: Binary XML file line #33: Duplicate id 0x7f090035, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)

它说我的xml文件在第33行有错误,但根据我的经验和我在网上搜索发现的,这就是我应该如何使用谷歌地图;

我的xml文件与谷歌地图代码;

<fragment
    android:id="@+id/googlemap"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

还有,我在和碎片一起工作。所以我无法扩展活动、碎片活动等。

public class GoogleMapsFragment extends Fragment {
 .....
}

共有1个答案

罗渝
2023-03-14

根据logcat输出,似乎要将同一个片段添加两次。这将导致IllegalStateExceptionIllegalArgumentException

解决方案是首先检查哪个片段当前在前台,如果它已经存在,则避免添加相同的片段:

Fragment f = (Fragment)getFragmentManager().findFragmentByTag("xyz_fragment");
if (f!=null && !f.isVisible() && !f.isAdded()) {

    ....

}
 类似资料: