【Debug-Fragment】Fragment has not been attached yet

java.lang.IllegalStateException: Fragment has not been attached yet.
        at android.support.v4.app.Fragment.instantiateChildFragmentManager(Fragment.java:2383)
        at android.support.v4.app.Fragment.getChildFragmentManager(Fragment.java:845)
        at xxx.assistant.fragment.xxxxxFragment.getRecyclerView(xxxxxFragment.java:72)
        at xxx.assistant.fragment.xxxxxFragment.startRecyclerView(xxxxxFragment.java:195)
        at vertu.assistant.fragment.xxxxxFragment.access$500(xxxxxFragment.java:33)
        at xxx.assistant.fragment.xxxxxFragment$4.onRequestxxSuccess(xxxxFragment.java:136)
        at vertu.assistant.request.xxRequest$1.onResponse(xxxxxxxxxx.java:209)

出问题的代码:

FragmentManager childFragmentManager = getChildFragmentManager();
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
recyclerView.setLayoutManager(gridLayoutManager);
XXXRecyclerAdapter adapter = new XXXRecyclerAdapter(getContext(), childFragmentManager, mList, mBannerLists, new IXXRecyclerUpdateCallback() {
...

参考:https://stackoverflow.com/questions/43562394/fragment-has-not-been-attached-yet

应该是操作了没有attach的Fragment,需要判断下if(mFragment.isAdded()){ //do }

于是在“getChildFragmentManager()”前添加判断:

if (!isAdded()) return;

先这样,再有报错再更新。。。

你可能感兴趣的:(Debug)