在将一个fragment替换到一个frameLayout的时候报错:html
code: transaction.replace(R.id.fragment_container, fragment2);java
错误: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.ide
缘由:spa
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {code
//View newsView = inflater.inflate(R.layout.fragment_news, container);
View newsView = inflater.inflate(R.layout.fragment_news, container,false);
return newsView;
}htm
出现此错误的根本问题是当前VIEW已经在别的View中,做为别的子View,如今又要将当前VIEW放在别的View中,就会抛出这类错误信息。blog
相同问题的其余文章:ci
http://www.cnblogs.com/shenbin/archive/2012/03/15/2398209.htmlrem
http://www.cnblogs.com/over140/archive/2013/06/06/3121354.htmlget