TonicArtos / SuperSLiM

A layout manager for the RecyclerView with interchangeable linear, grid, and staggered displays of views, all with configurable section headers including the sticky variety as specified in the material design docs.
http://tonicartos.nz
2.12k stars 296 forks source link

NPE in SectionData after findFirstVisibleItem is called. #95

Closed kingargyle closed 7 years ago

kingargyle commented 9 years ago

We got the following stack trace with 0.4.11, I haven't tried upgrading yet to 0.4.13: Caused by: java.lang.NullPointerException at com.tonicartos.superslim.SectionData.(SourceFile:36) at com.tonicartos.superslim.LayoutManager.findFirstVisibleItem(SourceFile:148) at com.tonicartos.superslim.LayoutManager.findFirstVisibleItemPosition(SourceFile:179)

OllieStrevel commented 9 years ago

I have the same issue, actually my RecyclerView has an EndLessScrollListener to append items, however, when i refresh (vía OnRefreshListener) i got the same NPE.

kingargyle commented 9 years ago

@TonicArtos any possibility of taking a look into this, this is affecting our production application with 0.4 branch. If you can point me in the general direction to try and fix the issue, I'm more than willing to provide a pull request.

kingargyle commented 9 years ago

For me this may be fixed by upgrading to version 0.4.13, I need to do some more testing to make sure.

OllieStrevel commented 9 years ago

I actually upgraded to 0.4.14, however my issue is I've added an ScrollListener to my RecycleView, so when I do refresh (With SwipeLayout) i got this NPE, I fixed this removing and adding the listener when correspond. If somebody has a better fix for this issue, tell me, but i'll keep on testing...

kingargyle commented 9 years ago

Ok for me this seems to be fixed with version 0.4.13. I'll leave open since @OllieStrevel got the issue by doing things a different way.

TonicArtos commented 9 years ago

@kingargyle Hi, I'm glad 0.4.13 seems to have resolved the problem. There were fixes to related code in 0.4.13, perhaps that is what fixed it. Well, I'll check to see what happened anyway.

@OllieStrevel I presume you mean 0.4.13. There is probably some state not being regenerated for some reason, causing the NPE. I haven't looked into what this is yet, but I'll get to it.

dabitdev commented 8 years ago

I am having similar crash with a LG-D393 and 0.4.13. For now, only reproducible in this device.

mOnScrollListener = new RecyclerView.OnScrollListener() {
      @Override
      public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        ....
        int mFirstVisibleItem = 0;
        try {
          mFirstVisibleItem = getLayoutManager().findFirstVisibleItemPosition();
        } catch (Exception e) {
          //Hacky fix to prevent crash because of Null Pointer Exception happenning in LG device
          e.printStackTrace();
        }
        ....
      }
TonicArtos commented 8 years ago

I know about the problem and there is a fix in the works. This problem is rooted in the original design of SuperSLiM and so I had to go back and start over. To see current progress you can check out the version5 branch.