替换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.的更多相关文章
- 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 ...
- 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 ...
- 【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 ...
- idea能用下划线替换红色报错吗?我色弱,用idea简直太痛苦了
看看下图的idea,如果某个类的包路径没有引进来,使用颜色来提示,这对于色弱的程序员简直是一种折磨,有没有可以改成eclipse的那种报错提示方式? 个人感觉idea真的没有eclipse友好,也许是 ...
- Type mismatch: cannot convert from MainFragment to Fragment 报错
源码: FragmentTransaction mFragmentTranscation = getSupportFragmentManager().beginTransaction(); Fragm ...
- Vue2.0用components替换render报错
怀疑是webpack配置的问题,改了一下午也没弄好.去群里问了一轮,也没个解决的. 在研究的过程中,发现了一篇好的讨论帖,看这个帖子能学到不少东西.暂时放弃这个问题的研究了,太费时间,要深入学习编译原 ...
- 关于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=" ...
- 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, ...
- 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 ...
随机推荐
- 2017.11.27 用Servlet在JSP中加入验证码
登陆界面 <%@ page pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...
- jQuery序列化表单为JSON对象
<form id="myform"> <table> <tr> <td>姓名:</td> <td> < ...
- MAC卸载/删除 Parallels Desktop虚拟机的方法
一些MAC用户在自己的电脑上安装了虚拟机之后,想要将它卸载,但是不知道该怎么做.今天小编就为大家带来了这个问题的解决方法. 解决方案(删除/卸载虚拟机 (VM): 1.启动Parallels Desk ...
- python读取mat文件
一.mat文件 mat数据格式是Matlab的数据存储的标准格式.在Matlab中主要使用load()函数导入一个mat文件,使用save()函数保存一个mat文件.对于文件 load('data.m ...
- cudaMalloc和cudaMallocPitch
原文链接 偶有兴趣测试了一下题目中提到的这两个函数,为了满足对齐访问数据,咱们平时可能会用到cudamallocPitch,以为它会带来更高的效率.呵呵,这里给出一段测试程序,大家可以在自己的机器上跑 ...
- js中的变量提升(Hoisting)
<script> function test(){ console.log(a); console.log(foo()); var a=1; function foo(){ return ...
- 刚学不久的python,自己稍微加工了一点,影响不大,因为博主很懒,所以格式什么的,就没有太在意了!
本人初学python,之前因为有接触过其他语言,但是并没有接触的太深,出于对一个hacker的向往,学习一下Linux和python再说,当然,也是为了高工资啦,啊哈哈哈! 一开始就是一个蛮有意思的小 ...
- JQuery基础原理 与实例 验证表单 省市联动 文本框判空 单选 复选 判空 下拉判空 确认密码判等
JQuery 基础原理 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- javascript中call,apply,bind的使用
不同点: 1.call():传参方式跟bind一样(都是以逗号隔开的传参方式),但是跟apply(以数组的形式传参)不一样, 2.bind(): 此方法应用后的情形跟call和apply不一样.该方法 ...
- python逻辑运算(not,and,or)总结
逻辑运算 1.在没有()的情况下not优先级高于and,and优先级高于or,即优先级关系为()>not>and>or,同一优先级从左往右计算 总结:a or b : 如果a = 0 ...