在將一個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