这里写自定义目录标题
RecyclerView奔溃完整报错:
java.lang.NullPointerException: Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$ViewHolder.itemView' on a null object reference
at androidx.recyclerview.widget.DefaultItemAnimator.runPendingAnimations(DefaultItemAnimator.java:157)
at androidx.recyclerview.widget.RecyclerView$2.run(RecyclerView.java:603)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1058)
at android.view.Choreographer.doCallbacks(Choreographer.java:865)
at android.view.Choreographer.doFrame(Choreographer.java:796)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1043)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7562)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
原因是使用缓存加载,刷新频繁且有移除项时,recyclerview默认的itemAnimator动画中holder未做空判断,导致奔溃
解决方案:
将默认动画去掉
recyclerView.itemAnimator = null