替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.

在将一个fragment替换到一个frameLayout的时候报错:

code: transaction.replace(R.id.fragment_container, fragment2);

错误:  java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child‘s parent first.

原因:

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

   //View newsView = inflater.inflate(R.layout.fragment_news, container);
        View newsView = inflater.inflate(R.layout.fragment_news, container,false);
        return newsView;
    }

出现此错误的根本问题是当前VIEW已经在别的View中,作为别的子View,现在又要将当前VIEW放在别的View中,就会抛出这类错误信息。

相同问题的其他文章:

http://www.cnblogs.com/shenbin/archive/2012/03/15/2398209.html

http://www.cnblogs.com/over140/archive/2013/06/06/3121354.html

替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.

时间: 2024-10-26 12:50:02

替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.的相关文章

Android-The specified child already has a parent. You must call removeView() on the child's parent first.

这个问题搞了我半天了,网上有很多人说需要找到该控件的parent后,让该parent 先remove需要添加的控件,然后在添加,如: if (view != null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) { parent.removeView(view); } } try { view = inflater.inflate(R.layout.fragment_main, container

The specified child already has a parent. You must call removeView() on the child's parent first.

<pre name="code" class="java"><span style="font-size:24px;">java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.</span> 今天写代码要给Al

Fragment(10)FragmentTransaction.add(id,Fragment)报错: No view found for id 0x****** for fragment

1.错误信息: 06-26 22:54:28.509: E/AndroidRuntime(20363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exe.custommenu/com.exe.custommenu.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0xaabbcc for fragmen

fragment报错

1. java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader I just solved this problem in Android API 8 machine (Samsung Galaxy S). Please change Activity class to FragmentActivity. public class FragmentLayout e

动态添加Fragment的报错信息

05-29 21:23:28.406: E/AndroidRuntime(23636): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.Main}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent

关于报错The specified child already has a parent的解决办法

报错信息为:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 首先,如果你看到这篇文章,说明你已经搜了很多篇了(首页可能字数都不够,但是又不甘心收获不能普度众生……),所以我想声明一下,你一定不要抱着直接找到源码解决问题的想法,要找方法,发现问题解决问题的方法! 好了,正如报错信息提示的

Android开发之自定义Dialog二次打开报错问题解决

之前自定义了一个AlertDialog对话框,第一次点击时正常,但第二次调用时会出现错误:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 关于这个错误纠结了我好久,在网上百度了也不少,但感觉解决效果都达不到自己想要的效果.网上的解释说是一个子视图指定了多个父视图.由此可以推断出,在第二

解决alaert.builder二次调用报错的bug

报错的代码是: The specified child already has a parent. You must call removeView() on the child's parent first 大致是说你的弹出框中的view已经绑定了一个paren,就是你的弹出框.当你再次调用显示的时候.他以为你又要绑定到一个新的窗体上去. 解决办法是每次显示之前都又一次填充设置view.例如以下:每次点击的时候调用: public void startClick(View view){ Lay

dovecot vsz_limit参造成foxmail、outlook等客户端工具接收邮件有时候报错

问题:dovecot并发数造成foxmail.outlook等客户端工具接收邮件有时候报错,关闭客户端工具后又可以了. /var/log/maillog日志有大量的报错: Jan 25 08:18:35 localhost dovecot: auth: Fatal: master: service(auth): child 60976 returned error 83 (Out of memory (service auth { vsz_limit=256 MB }, you may need