Very fast scrolling in some cases throws IndexOutOfBoundsException
Very fast scrolling with updating items can produce following exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: future.company.beside, PID: 15159
java.lang.IndexOutOfBoundsException: Invalid item position 3(3). Item count:3 future.company.beside.ext.cardstackview.CardStackView{150412c VFED..... ......ID 32,32-1048,1436 #7f0a004b app:id/cardStack}, adapter:future.company.beside.component.card.CardStackAdapter@70f57f5, layout:future.company.beside.ext.cardstackview.CardStackLayoutManager@ad3498a, context:future.company.beside.MainActivity@3609d2f
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5885)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at future.company.beside.ext.cardstackview.CardStackLayoutManager.update(CardStackLayoutManager.java:222)
at future.company.beside.ext.cardstackview.CardStackLayoutManager.scrollHorizontallyBy(CardStackLayoutManager.java:70)
at android.support.v7.widget.RecyclerView.scrollStep(RecyclerView.java:1829)
at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5067)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
As i understand this situation, new item hasn't been processed yet but was added in adapter.
Happens when adapter.itemCount < visibleCount, in this situation in update method loop working rule is i < getItemCount()
for (int i = state.topPosition; i < state.topPosition + setting.visibleCount && i < getItemCount(); i++) {
...
}
Solution:
Provide to update method RecyclerView.State which has getItemCount(). This count will be updated when new item will be measured.
I have the same issue.How to solve it?
@taomWTP how did you resolve the issue?
@yuyakaido why you close the issue without having solution ?
@richanshah did you find any solution??