java.lang.IllegalStateException: Fragment already added ListFragment异常的处理

时间:2022-12-05 20:32:32
1、new ListFragment()是一个空指针,就好像只是一个而已,而下面那种是新建多次.
setOnCreateFragment(new ListFragment());
public void setOnCreateFragment(Fragment fragment) {
return fragment;
}
2、fragment.newInstance();则是总是新建 
setOnCreateFragment(ListFragment.class); public void setOnCreateFragment(final Class<? extends Fragment> fragment) {        Fragment listFragment = null;        try {                listFragment = fragment.newInstance();            } catch (InstantiationException e) {                e.printStackTrace();            } catch (IllegalAccessException e) {                e.printStackTrace();        }        return listFragment; }
 本人只是知道大概,有哪位大神可以指导指导,在下感激不尽.