Why am I getting a null reference on my RecyclerView

后端 未结 5 735
攒了一身酷
攒了一身酷 2021-02-02 12:37

I am trying to use the RecyclerView in my fragments. It shows up fine for the first tab, but when I swipe to the second tab and then back to the first one I get the following er

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 13:16

    Reading the bug posted by Isaak, the best solution seems to be assigning the Layout Manager as soon as the view is inflated.

    In my case, I only had to assign it on onCreate to fix the problem:

    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    

提交回复
热议问题