【问题标题】:Replace fragment caused RecyclerView$ViewHolder.shouldIgnore()’ on a null object reference替换片段导致空对象引用上的 RecyclerView$ViewHolder.shouldIgnore()'
【发布时间】:2019-01-24 09:20:10
【问题描述】:

我在这里使用 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)

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

【问题讨论】:

  • 请分享您的片段交易代码
  • 你的 RecyclerView 适配器显然有一些奇怪的行为

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


【解决方案1】:

请遵循以下模式,它应该可以帮助您解决问题。我有同样的问题,我花了一段时间才最终弄清楚。

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

注意:无需添加“.addToBackStack(null)”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多