You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android12(Oppo/一加/真我)RecyclerView关联Choreographer空指针崩溃求助

RecyclerView 1.2.1在Android 12 Oppo/一加/真我设备上的Choreographer相关崩溃问题

问题详情

  • 使用组件:RecyclerView 版本 1.2.1
  • 复现环境:Android 12系统的Oppo、一加、真我设备
  • 现象:近期Firebase Crashlytics日志中突然出现多起与Choreographer相关的空指针崩溃,崩溃发生在RecyclerView组件内部逻辑中,目前尚未找到根治方案,寻求经验分享或解决方案。

崩溃栈信息1

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'androidx.recyclerview.widget.RecyclerView$p androidx.recyclerview.widget.RecyclerView.mLayout' on a null object reference in method 'int androidx.recyclerview.widget.RecyclerView$z.getChildCount()'
       at androidx.recyclerview.widget.RecyclerView$SmoothScroller.getChildCount(RecyclerView.java:12361)
       at androidx.recyclerview.widget.LinearSmoothScroller.onSeekTargetStep(LinearSmoothScroller.java:127)
       at androidx.recyclerview.widget.RecyclerView$SmoothScroller.onAnimation(RecyclerView.java:12337)
       at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5564)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1232)
       at android.view.Choreographer.doCallbacks(Choreographer.java:1029)
       at android.view.Choreographer.doFrame(Choreographer.java:925)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1217)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:233)
       at android.os.Looper.loop(Looper.java:344)
       at android.app.ActivityThread.main(ActivityThread.java:8212)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

崩溃栈信息2

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int androidx.recyclerview.widget.RecyclerView.getChildLayoutPosition(android.view.View)' on a null object reference
       at androidx.recyclerview.widget.RecyclerView$SmoothScroller.getChildPosition(RecyclerView.java:12354)
       at androidx.recyclerview.widget.RecyclerView$SmoothScroller.onChildAttachedToWindow(RecyclerView.java:12381)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8905)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8860)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8848)
       at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1645)
       at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
       at androidx.recyclerview.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1395)
       at androidx.recyclerview.widget.LinearLayoutManager.scrollHorizontallyBy(LinearLayoutManager.java:1124)
       at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1969)
       at androidx.recyclerview.widget.RecyclerView$SmoothScroller.onAnimation(RecyclerView.java:12316)
       at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5564)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1232)
       at android.view.Choreographer.doCallbacks(Choreographer.java:1029)
       at android.view.Choreographer.doFrame(Choreographer.java:925)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1217)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:233)
       at android.os.Looper.loop(Looper.java:344)
       at android.app.ActivityThread.main(ActivityThread.java:8212)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

问题背景

该崩溃属于RecyclerView组件内部的空指针问题,核心原因是SmoothScroller在RecyclerView实例已被销毁后,仍尝试访问其内部引用。此问题已被Google官方问题追踪平台记录,官方确认该问题特定出现在Android 12的部分设备上,目前RecyclerView 1.2.1版本暂未修复。

临时解决方案建议

  • 在RecyclerView所在页面销毁时(如Activity的onDestroy方法、Fragment的onDestroyView方法),主动调用recyclerView.stopScroll(),终止所有正在进行的平滑滚动操作,避免SmoothScroller在组件销毁后继续执行回调。
  • 自定义SmoothScroller子类,在onSeekTargetStep、onChildAttachedToWindow等回调方法中先检查RecyclerView实例是否为null,再执行后续逻辑。
  • 持续关注RecyclerView的版本更新,等待官方发布修复补丁。

内容的提问来源于stack exchange,提问作者Dileep Bhadauria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 02:10:57