Cotlin keep stopping error java.lang.ArrayIndexOutOfBoundsException: length=2; index=2

Asked 1 weeks ago, Updated 1 weeks ago, 2 views

I get this error when I run the app, but I don't know what the problem is.

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.sharing, PID: 16912
    java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
        at java.util.Arrays$ArrayList.get(Arrays.java:3766)
        at ui.ViewPagerAdapter.onBindViewHolder(ViewPagerAdapter.kt:33)
        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
        at androidx.recyclerview.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1391)
        at androidx.recyclerview.widget.LinearLayoutManager.scrollHorizontallyBy(LinearLayoutManager.java:1116)
        at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1838)
        at androidx.recyclerview.widget.RecyclerView$SmoothScroller.onAnimation(RecyclerView.java:11920)
        at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5390)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:721)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

kotlin

2022-09-20 10:43

1 Answers

In the message

java.lang.ArrayIndexOutOfBoundsException: length=2; index=2

There's a part.

A problem occurred when an element with an index of 2 was requested in an array of length 2.

Look at line 33 of the ViewPagerAdapter.kt source.


2022-09-20 10:43

If you have any answers or tips


© 2022 pinfo. All rights reserved.