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

来源:互联网 发布:百度软件管家官方下载 编辑:程序博客网 时间:2024/06/14 23:13
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
以上问题是由于布局文件已经有了父视图,再次加载会出现重复,导致错误,去除窗体的原始父窗体就可以了。

1. 遇到问题是在fragment中,当获取view的时候报错了,示例为
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    return inflater.inflate(R.layout.slidingdrawer, container, false);
}

最后一个参数没有写,默认为true,代表依附于ViewGroup,这样布局就有了父窗体,再次添加到其他view里面就会报错,所以应该写上false,问题解决。


文章来自:http://blog.163.com/zzf_soft/blog/static/1340017472013111804322552/

0 0
原创粉丝点击