当充气片段,previously膨胀的应用程序崩溃 [英] When inflating fragment which was previously inflated app crashes

查看:147
本文介绍了当充气片段,previously膨胀的应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序加载和意见 EventFragment.java 可显示地图。当您单击另一个选项卡片段它加载在精细,当你再回到第一个选项卡(图)崩溃和错误的:

The app loads and views EventFragment.java which displays a map. When you click another tab fragment it loads that in fine, when you go back to the first tab (the map) it crashes and errors with:

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文件:

So reading that it says the XML file line 5. This is the XML file:

<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>

这恰好是&LT;片段所以..错误与片段是吗?我真的不知道怎么回事。任何想法,为什么这会引发错误?

Which happens to be <fragment so.. the error is with the fragment yeah? I dont really know whats going on. Any ideas why this throws an error?

推荐答案

我一直在争取这一整天同样的问题今天。我得到了我先前的工作。这里就是我所做的:当改变片段显示,我首先删除旧mapFragment,然后添加新的整理碎片时做什么,我通常做

I've been fighting with this same issue all day today. I got mine working earlier. Here's what I did: When changing the fragment showing, I first remove the old mapFragment, then do what I normally do when adding new fragments.

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,我删除了previous片段然后再次膨胀与mapFragment的观点:

When I want to view the mapFragment again, I remove the previous fragment then inflate the view with the mapFragment again:

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()删除(oldMapFrag).commit(); 工作的第一步,因为你不应该能够去除XML定义的片段,但这为我工作。我希望它能帮助。

I don't know why getSupportFragmentManager().beginTransaction().remove(oldMapFrag).commit(); works in the first step because you shouldn't be able to remove fragments defined in XML, but this does work for me. I hope it helps.

这篇关于当充气片段,previously膨胀的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆