gpt4 book ai didi

java - 当膨胀之前膨胀的 fragment 应用程序崩溃时

转载 作者:太空宇宙 更新时间:2023-11-03 12:57:24 26 4
gpt4 key购买 nike

应用加载和查看 EventFragment.java显示 map 。当您单击另一个选项卡 fragment 时,它会正常加载,当您返回第一个选项卡( map )时,它会崩溃并出现错误:

07-03 14:13:54.640: E/AndroidRuntime(11565): FATAL EXCEPTION: main
07-03 14:13:54.640: E/AndroidRuntime(11565): android.view.InflateException: Binary XML file line #5: Error inflating class fragment
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-03 14:13:54.640: E/AndroidRuntime(11565): at co.uk.thesomewhere.townpearlfest.EventFragment.onCreateView(EventFragment.java:48)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1264)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.os.Handler.handleCallback(Handler.java:587)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.os.Looper.loop(Looper.java:143)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.app.ActivityThread.main(ActivityThread.java:4196)
07-03 14:13:54.640: E/AndroidRuntime(11565): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 14:13:54.640: E/AndroidRuntime(11565): at java.lang.reflect.Method.invoke(Method.java:507)
07-03 14:13:54.640: E/AndroidRuntime(11565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-03 14:13:54.640: E/AndroidRuntime(11565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-03 14:13:54.640: E/AndroidRuntime(11565): at dalvik.system.NativeStart.main(Native Method)
07-03 14:13:54.640: E/AndroidRuntime(11565): Caused by: java.lang.IllegalArgumentException: Binary XML file line #5: Duplicate id 0x7f05000b, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
07-03 14:13:54.640: E/AndroidRuntime(11565): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
07-03 14:13:54.640: E/AndroidRuntime(11565): ... 19 more
07-03 14:13:56.280: I/Process(11565): Sending signal. PID: 11565 SIG: 9

所以读到它说 XML 文件第 5 行。这是 XML 文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

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

<Button
android:id="@+id/btn_filerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:drawableRight="@drawable/magglasswhite"
android:background="@android:color/transparent"
android:onClick="filterView" />

</FrameLayout>

恰好是 <fragment所以..错误与 fragment 有关吗?我真的不知道发生了什么。知道为什么这会引发错误吗?

最佳答案

我今天一整天都在为同样的问题而战。我让我的工作更早了。这是我所做的:当更改显示的 fragment 时,我首先删除旧的 mapFragment,然后执行我通常在添加新 fragment 时所做的事情。

Fragment oldMapFrag = getSupportFragmentManager().findFragmentById(R.id.map);
if(oldMapFrag != null) {
getSupportFragmentManager().beginTransaction().remove(oldMapFrag).commit();
manager.popBackStack();
ViewGroup container = (ViewGroup)findViewById(R.id.content);
if(container != null)
container.removeAllViews();
}

当我想再次查看 mapFragment 时,我删除了之前的 fragment ,然后再次使用 mapFragment 扩充 View :

Fragment currentFrag = getSupportFragmentManager().findFragmentById(R.id.content);
if(currentFrag != null) {
getSupportFragmentManager().beginTransaction().remove(currentFrag).commit();
manager.popBackStack();
}
View mapView = inflator.inflate(R.layout.store_finder, container, true);

我不知道为什么 getSupportFragmentManager().beginTransaction().remove(oldMapFrag).commit(); 在第一步工作,因为你不应该能够删除定义的 fragment XML,但这对我有用。希望对您有所帮助。

关于java - 当膨胀之前膨胀的 fragment 应用程序崩溃时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17449124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com