二进制XML文件第26行:重复的ID,标签为空或父ID为另一个片段 [英] Binary XML file line #26: Duplicate id, tag null, or parent id with another fragment

查看:471
本文介绍了二进制XML文件第26行:重复的ID,标签为空或父ID为另一个片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个片段插入另一个片段,并且我成功地做到了这一点,直到我第一次午餐主片段为止,但是当我尝试重新加载该片段时,应用程序崩溃了,并且我有此错误:

 原因:java.lang.IllegalArgumentException:二进制XML文件行#26:
复制id 0x7f0e00e2,标记null或父ID 0xffffffff,以及com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
片段>

这是我的片段

  @Override 
public View onCreateView( LayoutInflater充气器,ViewGroup容器,
捆绑保存的InstanceState){

View rootView = inflater.inflate(R.layout.source_destination,container,false);
PlaceAutocompleteFragment sourcr_autocompleteFragment =(PlaceAutocompleteFragment)
getActivity()。getFragmentManager()
.findFragmentById(R.id.sourcr_autocomplete_fragment);
返回rootView;

//列表项

}

这是我的XML

 <?xml version = 1.0 encoding = utf-8 ?> 
< LinearLayout xmlns:android = http://schemas.android.com/apk/res/android
android:orientation = vertical
android:padding = 10dp
android:background = @ color / colorPrimary
android:layout_width = match_parent
android:layout_height = match_parent>
< android.support.v7.widget.CardView
android:layout_width = match_parent
android:layout_height = wrap_content
android:layout_marginTop = @ dimen / margin_medium
android:layout_marginBottom = @ dimen / margin_medium>

<片段
android:id = @ + id / sourcr_autocomplete_fragment
android:name = com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
android:layout_width = match_parent
android:layout_height = wrap_content />

< /android.support.v7.widget.CardView>
< / LinearLayout>


解决方案

我遇到了同样的问题并且可以解决通过删除 onDismiss 回调中的片段。

  @Override 
public void onDismiss( DialogInterface对话框){
super.onDismiss(dialog);

if(getActivity()!= null){
FragmentManagerfragmentManager = getActivity()。getFragmentManager();
片段片段= fragmentManager.findFragmentById(R.id.sourcr_autocomplete_fragment);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.remove(fragment);
fragmentTransaction.commit();
}
}


I'm trying to insert a fragment to another and I’ve succeed to do this until I’ve lunch the main fragment for the first time it's working but when I’m trying to reload the fragment the app crash, and i have this error:

Caused by: java.lang.IllegalArgumentException: Binary XML file line #26:
Duplicate id 0x7f0e00e2, tag null, or parent id 0xffffffff with another
fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment

This is my fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View  rootView = inflater.inflate(R.layout.source_destination,container, false);
PlaceAutocompleteFragment sourcr_autocompleteFragment = (PlaceAutocompleteFragment)
          getActivity().getFragmentManager()
.findFragmentById(R.id.sourcr_autocomplete_fragment);
return rootView;

// List item

}

This is my XML

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:padding="10dp"
        android:background="@color/colorPrimary"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
       <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_medium"
            android:layout_marginBottom="@dimen/margin_medium">

            <fragment
                android:id="@+id/sourcr_autocomplete_fragment"    
                android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"           
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />

        </android.support.v7.widget.CardView>
    </LinearLayout>

解决方案

I just ran into the same problem and could solve it by removing the fragment in the onDismiss callback.

@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);

    if (getActivity() != null) {
        FragmentManager fragmentManager = getActivity().getFragmentManager();
        Fragment fragment = fragmentManager.findFragmentById(R.id.sourcr_autocomplete_fragment);
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.remove(fragment);
        fragmentTransaction.commit();
    }
}

这篇关于二进制XML文件第26行:重复的ID,标签为空或父ID为另一个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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