BaseRecyclerViewAdapterHelper
BaseRecyclerViewAdapterHelper copied to clipboard
调用BaseNodeAdapter的nodeSetData()和nodeRemoveData()操作列表最后一个条目会崩溃报错
报错方法: /** * 从数组中移除 * @param position Int * @return Int 被移除的数量 */ private fun removeNodesAt(position: Int): Int { if (position >= data.size) { return 0 } // 记录被移除的item数量 var removeCount = 0
// 先移除子项
removeCount = removeChildAt(position)
// 移除node自己
this.data.removeAt(position)
removeCount += 1
val node = this.data[position]
// 移除脚部
if (node is NodeFooterImp && node.footerNode != null) {
this.data.removeAt(position)
removeCount += 1
}
return removeCount
}
崩溃日志: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionBaseViewHolder{4b14998 position=23 id=-1, oldPos=-1, pLpos:-1 no parent} androidx.recyclerview.widget.RecyclerView{a59f2b1 VFED.V... ........ 0,100-720,1363 #7f0a03da app:id/rv_friend}, adapter:com.nn.accelerator.adapter.chat.ChatFriendAdapter@6247396, layout:androidx.recyclerview.widget.LinearLayoutManager@4c11b17, context:com.nn.accelerator.ui.activity.MainActivity@6cdc5f7 at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:6087) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6270) 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:914) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:225) at android.app.ActivityThread.main(ActivityThread.java:7563) 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:994)
遇到同样的问题了
我也遇到了
我也遇到了,有什么解决办法吗
遇到同样的问题了,removeNodesAt(position: Int)这个函数有问题
`// 移除node自己 this.data.removeAt(position) removeCount += 1
val node = this.data[position] `
移除自己了 在获取自己,如果是最后一条数据,那就会IndexOutOfBoundsException 函数问题
我也遇到了
nodeRemoveData 也报错了
@ChadCym 这个问题能修复吗
好像有点印象,我解决的办法好像是去继承那个adapter,就是在报错那里判断一下就可以了吧。后续应该修复了吧
薛雨森 Android开发工程师 玛格全屋定制
联系我
------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年1月13日(星期四) 中午11:38 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [CymChad/BaseRecyclerViewAdapterHelper] 调用BaseNodeAdapter的nodeSetData()和nodeRemoveData()操作列表最后一个条目会崩溃报错 (#3344)
@ChadCym 这个问题能修复吗
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
最新版本这个问题还是有的
哦哦,那我不清楚哦,你可以去问问作者看有没有把这个问题处理好并更新
薛雨森 Android开发工程师 玛格全屋定制
联系我
------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年1月13日(星期四) 中午11:44 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [CymChad/BaseRecyclerViewAdapterHelper] 调用BaseNodeAdapter的nodeSetData()和nodeRemoveData()操作列表最后一个条目会崩溃报错 (#3344)
最新版本这个问题还是有的
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
可能的解决方案供参考:https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/3065#issuecomment-1019767558
同样遇到这样的问题,有老哥有处理方案么