java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2

Stack Overflow | Chirag | 1 month ago
tip
Do you find the tips below useful? Click on the to mark them and say thanks to poroszd and Rafael Fischer Viola . Or join the community to write better ones.
  1. 0
    samebug tip
    Call notifyDataSetChanged instead of notifyItemRemoved due to a bug in RecyclerView
  2. 0

    IndexOutOfBoundException when passing data to firebase on clicking a button

    Stack Overflow | 1 month ago | Chirag
    java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
  3. 0
    samebug tip
    This probably occurs because you are calling notifyItemInserted(position);, notifyItemChanged(position), or notifyItemRemoved(position); from a background thread (or from a callback, which runs on a background thread). Use a Handler to solve it.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    samebug tip
    Try to reset the previous listener before making any changes to the view.
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.IndexOutOfBoundsException

    Invalid index 2, size is 2

    at java.util.ArrayList.throwIndexOutOfBoundsException()
  2. Java RT
    ArrayList.get
    1. java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
    2. java.util.ArrayList.get(ArrayList.java:308)
    2 frames
  3. com.notadeveloper.app
    CartAdapter.onBindViewHolder
    1. com.notadeveloper.app.sgnpharmacy.CartAdapter.onBindViewHolder(CartAdapter.java:66)
    2. com.notadeveloper.app.sgnpharmacy.CartAdapter.onBindViewHolder(CartAdapter.java:31)
    2 frames
  4. Android v7
    RecyclerView.onMeasure
    1. android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6308)
    2. android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6341)
    3. android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5287)
    4. android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5550)
    5. android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5392)
    6. android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5388)
    7. android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2149)
    8. android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1533)
    9. android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1496)
    10. android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:593)
    11. android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3535)
    12. android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2979)
    12 frames
  5. Android Platform
    FrameLayout.onMeasure
    1. android.view.View.measure(View.java:18807)
    2. android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
    3. android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
    4. android.view.View.measure(View.java:18807)
    5. android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1283)
    6. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    7. android.widget.ScrollView.onMeasure(ScrollView.java:340)
    8. android.view.View.measure(View.java:18807)
    9. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
    10. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    10 frames
  6. Android v7
    ContentFrameLayout.onMeasure
    1. android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
    1 frame
  7. Android Platform
    ViewGroup.measureChildWithMargins
    1. android.view.View.measure(View.java:18807)
    2. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
    2 frames
  8. Android v7
    ActionBarOverlayLayout.onMeasure
    1. android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
    1 frame
  9. Android Platform
    FrameLayout.onMeasure
    1. android.view.View.measure(View.java:18807)
    2. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
    3. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    4. android.view.View.measure(View.java:18807)
    5. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
    6. android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1458)
    7. android.widget.LinearLayout.measureVertical(LinearLayout.java:746)
    8. android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
    9. android.view.View.measure(View.java:18807)
    10. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
    11. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    11 frames
  10. Android
    PhoneWindow$DecorView.onMeasure
    1. com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
    1 frame
  11. Android Platform
    Handler.handleCallback
    1. android.view.View.measure(View.java:18807)
    2. android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2108)
    3. android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1224)
    4. android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1460)
    5. android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1115)
    6. android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6023)
    7. android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    8. android.view.Choreographer.doCallbacks(Choreographer.java:670)
    9. android.view.Choreographer.doFrame(Choreographer.java:606)
    10. android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    11. android.os.Handler.handleCallback(Handler.java:739)
    11 frames