I'm getting some crash reports about a NullPointerException happening in StaggeredGridLayoutManager. Looks like around 10% of my users are suffering this issue.
I have a very basic RecyclerView with a basic adapter, nothing special, and I did try to reproduce this error in my devices with no luck at all.
This is the raw report I'm getting reported:
java.lang.NullPointerException
at android.support.v7.widget.StaggeredGridLayoutManager.recycleFromStart(StaggeredGridLayoutManager.java:1661)
at android.support.v7.widget.StaggeredGridLayoutManager.recycle(StaggeredGridLayoutManager.java:1529)
at android.support.v7.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1471)
at android.support.v7.widget.StaggeredGridLayoutManager.scrollBy(StaggeredGridLayoutManager.java:1846)
at android.support.v7.widget.StaggeredGridLayoutManager.scrollVerticallyBy(StaggeredGridLayoutManager.java:1764)
at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:3062)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:572)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
I have no clue about what is happening. I thought that maybe I was setting the adapter before the layout manager but nope, it's not the case.
I hope somebody can throw some light over this.
Thanks in advance!
UPDATE:
I'm copying some code from my app related to the RecyclerView.
This code is from a Fragment:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView.LayoutManager layout = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)
mRecyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);
mRecyclerView.setLayoutManager(layout);
mRecyclerView.setAdapter(mAdapter);
}
And this is from the adapter, specifically the method that sets the adapter items:
public void setItems(List<String> items) {
mItems.clear();
mItems.addAll(items);
notifyDataSetChanged();
}