您的位置:首页 > 其它

替换Fragment 报错 The specified child already has a parent. You must call removeView()

2014-10-10 15:37 651 查看
原文 /article/6104758.html

在将一个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中,就会抛出这类错误信息。

相同问题的其他文章:

/article/6077653.html

/article/4602863.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐