RecyclerView列表滑动空指针问题
作者:互联网
1.问题现象
RecyclerView快速下拉,同时在分页加载数据,当数据很多时,则会出现空指针问题
出错信息如下所示
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)
2.解决方法
关闭RecyclerView更新动画
RecyclerView.getItemAnimator().setAddDuration(0);RecyclerView.getItemAnimator().setChangeDuration(0);RecyclerView.getItemAnimator().setMoveDuration(0);RecyclerView.getItemAnimator().setRemoveDuration(0);((SimpleItemAnimator) RecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
标签:widget,java,support,SourceFile,滑动,android,RecyclerView,指针 来源: https://blog.51cto.com/u_15091798/2782959