Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IndexOutOfBoundsException RecyclerView #25

Open
stevendobrien opened this issue Feb 6, 2016 · 4 comments
Open

java.lang.IndexOutOfBoundsException RecyclerView #25

stevendobrien opened this issue Feb 6, 2016 · 4 comments

Comments

@stevendobrien
Copy link

Just downloaded this app, and deployed. I see Toolbar above and then this:

Android 4.0.3 device.
compileSdkVersion 23
buildToolsVersion "23.0.2"

Device: SHV-E160S

02-06 23:58:07.109 13909-13909/io.github.froger.instamaterial E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{41933fb0 position=7 id=-1, oldPos=0, pLpos:0 scrap [attachedScrap] tmpDetached not recyclable(1) no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4251)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4382)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2864)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1037)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:747)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1156)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:760)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1634)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1492)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1405)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1634)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1492)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1405)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1634)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1492)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1405)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
at android.view.View.layout(View.java:11447)
at android.view.ViewGroup.layout(ViewGroup.java:4224)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1633)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2590)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4512)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.

@rohitpal440
Copy link

Hi! this kind of Problem arises when you are changing the dataset of adapter and performing scroll operation at same time. You can avoid this by blocking the scroll operation after required dataset is downloaded and adapter's dataset being updated. After that, you can unblock the scrolling operation for user.

@yigit
Copy link

yigit commented Jul 10, 2018

changing adapter data source while RV is scrolling does not crash recyclerview.
It happens if something is wrong in your events (e.g. you change the adapter from another thread or change it on the main thread but dispatch later).

@yigit
Copy link

yigit commented Jul 10, 2018

also the exception clearly states that data is inconsistent (which happens when your adapter updates are inconsistent)

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{41933fb0 position=7 id=-1, oldPos=0, pLpos:0 scrap [attachedScrap] tmpDetached not recyclable(1) no parent}

@ranjeetscience
Copy link

Then what is the solution to this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants