天天看點

【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 call removeView() on the child's parent first.

資訊補充:

使用FragmentActvitiy + Fragment

錯誤原因:

    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.preference_fragment, container);

解決辦法: 

View v = inflater.inflate(R.layout.preference_fragment, container, false);

補充資訊:

導緻此錯誤并不一定就是這個原因,大家也能搜到很多其他的原因,這裡備注一下。 

之前使用ActionBar裡面的Fragment好像是可以的。 

繼續閱讀