在将一个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.的更多相关文章

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

    在ViewPager中,用Fragment显示页面时,报错: java.lang.IllegalStateException: The specified child already has a pa ...

  2. android 异常信息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 p ...

  3. 【Android异常】The specified child already has a parent. You must call removeView() on the child's parent first.

    错误信息: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must ...

  4. idea能用下划线替换红色报错吗?我色弱,用idea简直太痛苦了

    看看下图的idea,如果某个类的包路径没有引进来,使用颜色来提示,这对于色弱的程序员简直是一种折磨,有没有可以改成eclipse的那种报错提示方式? 个人感觉idea真的没有eclipse友好,也许是 ...

  5. Type mismatch: cannot convert from MainFragment to Fragment 报错

    源码: FragmentTransaction mFragmentTranscation = getSupportFragmentManager().beginTransaction(); Fragm ...

  6. Vue2.0用components替换render报错

    怀疑是webpack配置的问题,改了一下午也没弄好.去群里问了一轮,也没个解决的. 在研究的过程中,发现了一篇好的讨论帖,看这个帖子能学到不少东西.暂时放弃这个问题的研究了,太费时间,要深入学习编译原 ...

  7. 关于MyEclipse启动报错:Error starting static Resources;下面伴随Failed to start component [StandardServer[8005]]; A child container failed during start.的错误提示解决办法.

    最后才发现原因是Tomcat的server.xml配置文件有问题:apache-tomcat-7.0.67\conf的service.xml下边多了类似与 <Host appBase=" ...

  8. Fragment+FragmentActivity出现The specified child already has a parent. You must call removeView() on the child's parent first.

    这个异常是出现在Fragment中的onCreateView方法中初始化布局时发生的. View view = inflater.inflate(R.layout.fragment3_layout, ...

  9. vue报错 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's

    [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...

随机推荐

  1. npm包发布过程

    在上一章节中,我封装了一个基于react的树状组件,后来想把它发布到npm上,下面主要介绍一下发布过程中遇到的问题: 1.去注册npm账号,注册地址(https://www.npmjs.com), 再 ...

  2. python模块之正则

    re模块 可以读懂你写的正则表达式 根据你写的表达式去执行任务 用re去操作正则 正则表达式 使用一些规则来检测一些字符串是否符合个人要求,从一段字符串中找到符合要求的内容.在线测试网站:http:/ ...

  3. axios 二进制流导出

    axios 二进制流导出 axios({ url: 'http://xxx', method:'get', data:{}, headers:{ 'ContentType': 'application ...

  4. 你的 maven 如何使用

    maven把你从痛苦的找包中解脱,让你感觉如此神奇,也让你的项目能够如此之小--功能一 依赖管理  (pom.xml 项目对象模型配置文件) 没有对比就没有伤害 maven让你可以随意增加删除项目的功 ...

  5. Python 创建项目、应用

    1.创建项目 django-admin startproject TestPython 2.创建应用 python3 manage.py startapp books 3.目录讲解 ├── TestP ...

  6. Ajax跨域请求以及乱码解决

    Ajax跨域请求2种解决方法 1 ) 什么叫跨域请求,协议,域名,端口号,其中一样不同都称跨域; 第一种:使用script标签发送请求; //创建一个script标签; var v_element=d ...

  7. springboot+Druid+mybatis整合

    一.添加Druid.MySQL连接池.mybatis依赖 <!--整合Druid--> <dependency> <groupId>com.alibaba</ ...

  8. ELK+kafka日志处理

    此次使用kafka代替redis,elk集群搭建过程请参考:https://www.cnblogs.com/dmjx/p/9120474.html kafka名词解释: 1.话题(Topic):是特定 ...

  9. 一次完整的http请求处理过程

    一次完整的HTTP请求需要的7个步骤 HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1:建立TCP连接 在HTTP工作开始之前,Web浏览器首先 ...

  10. xml解析之stax

    博文引自:http://zangweiren.iteye.com/blog/647334 Java 6.0对XML支持的新特性有许多方面.比如StAX.针对XML-Web服务的Java架构(JAX-W ...