【发布时间】:2021-11-19 17:59:42
【问题描述】:
我在 Firebase Crashlytics 上收到以下错误,它是随机发生的。我正在使用 EndlessRecyclerview
致命异常:java.lang.IndexOutOfBoundsException 检测到不一致。无效的视图支架适配器 positionProgressViewHolder{4950d13 position=73 id=-1, oldPos=-1, pLpos:-1 no parent} com.sportstigeratoz.utils.customView.EndlessRecyclerView{815d3c9 VFED..... ...... .. 0,0-1080,1554 #7f0a0302 app:id/recycler_view},适配器:com.sportstigeratoz.utils.customView.EndlessRecyclerView$AdapterWrapper@e489ace,布局:com.sportstigeratoz.utils.customView.InConsisTencyLinearLayoutManager@d68ddef,上下文: com.sportstigeratoz.ui.matchDetails.activities.MatchDetailsActivity@e00f70 androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition
有人遇到过这个问题吗?
解决办法是什么?
我已经尝试创建 CustomLinearLayoutManager 并覆盖其方法 onLayoutChildren 以在异常发生时捕获异常但不幸的是,即使尝试此操作后应用程序也会崩溃
但是,如果可能的话,我想更好地理解这个问题(也许从源头上解决它)
这个bug不容易复现,但一旦发生就致命。
完整的堆栈跟踪:
Fatal Exception: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionProgressViewHolder{4950d13 position=73 id=-1, oldPos=-1, pLpos:-1 no parent} com.sportstigeratoz.utils.customView.EndlessRecyclerView{815d3c9 VFED..... ........ 0,0-1080,1554 #7f0a0302 app:id/recycler_view}, adapter:com.sportstigeratoz.utils.customView.EndlessRecyclerView$AdapterWrapper@e489ace, layout:com.sportstigeratoz.utils.customView.InConsisTencyLinearLayoutManager@d68ddef, context:com.sportstigeratoz.ui.matchDetails.activities.MatchDetailsActivity@e00f70
at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5974)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6158)
at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:7617)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
【问题讨论】:
-
你在 ViewHolder 的某处使用
getAdapterPostion()吗? -
不,Viewholder中没有这种方法
标签: android firebase android-recyclerview crash indexoutofboundsexception