RecyclerView list sliding null pointer problem

RecyclerView pulls down quickly and loads data in pages at the same time. When there is a lot of data, there will be a null pointer problem

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
  	at android.support.v7.widget.ac$2.a(SourceFile:395)
  	at android.support.v17.leanback.widget.GridLayoutManager.c(SourceFile:1023)
  	at android.support.v17.leanback.widget.GridLayoutManager$2.b(SourceFile:1587)
  	at android.support.v17.leanback.widget.u.b(SourceFile:388)
  	at android.support.v17.leanback.widget.GridLayoutManager.A(SourceFile:1681)
  	at android.support.v17.leanback.widget.GridLayoutManager.y(SourceFile:2065)
  	at android.support.v17.leanback.widget.GridLayoutManager.scrollVerticallyBy(SourceFile:2010)
  	at android.support.v7.widget.RecyclerView$s.run(SourceFile:4413)
  	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:775)
  	at android.view.Choreographer.doCallbacks(Choreographer.java:588)
  	at android.view.Choreographer.doFrame(Choreographer.java:557)
  	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:761)
  	at android.os.Handler.handleCallback(Handler.java:739)
  	at android.os.Handler.dispatchMessage(Handler.java:95)
  	at android.os.Looper.loop(Looper.java:135)
  	at android.app.ActivityThread.main(ActivityThread.java:5276)
  	at java.lang.reflect.Method.invoke(Native Method)
  	at java.lang.reflect.Method.invoke(Method.java:372)
  	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)`

Solution: Turn off the RecyclerView update animation

recyclerView.getItemAnimator().setAddDuration(0);
recyclerView.getItemAnimator().setChangeDuration(0);
recyclerView.getItemAnimator().setMoveDuration(0);
recyclerView.getItemAnimator().setRemoveDuration(0);
((SimpleItemAnimator) RecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

Guess you like

Origin blog.csdn.net/xiaopihair123/article/details/131286697