InstaMaterial
InstaMaterial copied to clipboard
java.lang.IndexOutOfBoundsException RecyclerView
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.
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.
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).
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}
Then what is the solution to this problem?