在空对象引用上替换导致RecyclerView $ ViewHolder.shouldIgnore()’的片段

时间:2018-08-17 10:37:35

标签: android android-fragments android-recyclerview null leanback

我在这里使用的是android TV leanback示例, https://github.com/googlesamples/androidtv-Leanback

当我尝试像这样替换MainFragment中的片段时

getFragmentManager().beginTransaction().replace(R.id.main_frame, SampleFragment)
.addToBackStack(null).commit();

它崩溃

  

android.support.v7.widget.RecyclerView $ ViewHolder.shouldIgnore()”位于   空对象引用       在android.support.v7.widget.RecyclerView.findMinMaxChildLayoutPositions(RecyclerView.java:3989)

即使我替换为空白片段,它也会发生

1 个答案:

答案 0 :(得分:0)

Please follow the following pattern and it should help you resolve the issue. I had the same exact issue and took me awhile to figure it out finally.

 FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.replace(R.id.fragment_container, destinationFragment, null);
            ft.commit();

Note: No need to add ".addToBackStack(null)"