fragment The specified child already has a parent. You must call removeView()

时间:2023-03-10 07:06:59
fragment The specified child already has a parent. You must call removeView()

在切换Fragment的时候出现:The specified child already has a parent. You must call removeView()异常。

错误主要出在Fragment中的oncreateview方法中。

可能引起错误的写法:

View view = inflater.inflate(R.layout.indexfragment_layout, container);

  正确写法:

View view = inflater.inflate(R.layout.indexfragment_layout, container,
false);

  具体原因暂不详,希望知道的同学告知一下,谢谢。