0

I have a RecyclerView with multiple types of item view which contains TextView, ImageView and Exoplayer.

Whenever the user wants to delete an item from the list, I simply remove that item from the ArrayList and call notifyItemRemoved(p) method of the adapter of RecyclerView.

It was working fine till now but recently the app started crashing with Inconsistency detected Exception.

Following is the error from Log:

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 1(offset:-1).state:10 android.support.v7.widget.RecyclerView{b357202 VFED..... ......ID 0,0-1080,1680 #7f0900f1 app:id/home_recyclerview_feeds}, adapter:module.adapter.feed_adapter.FeedAdapter@e0a5713, layout:android.support.v7.widget.LinearLayoutManager@ca10d50, context:com.dzlyoum.android.HomeActivity@5d3ac7f
                                                   at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5622)
                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5557)
                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5553)
                                                   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
                                                   at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
                                                   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
                                                   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:618)
                                                   at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3644)
                                                   at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3408)
                                                   at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3962)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132)
                                                   at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                   at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
                                                   at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:869)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                   at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                   at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                   at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
                                                   at android.view.View.layout(View.java:16669)
                                                   at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                   at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2207)
                                                   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1963)
                                                   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
                                                   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6064)
                                                at android.view.Choreographer$CallbackRecord.run(Choreog

Following is the delete method I am using:

feedDetailList.remove(position);
feedAdapter.notifyItemRemoved(position);
  • `IndexOutOfBoundsException`, index is out of range. Please update your code – phatnhse Mar 16 '18 at 04:16
  • 1
    There is a discussion on this point : https://stackoverflow.com/questions/30220771/recyclerview-inconsistency-detected-invalid-item-position – DynamicMind Mar 16 '18 at 04:24
  • 1
    And here too : https://github.com/realm/realm-android-adapters/issues/76 – DynamicMind Mar 16 '18 at 04:24
  • @DynamicMind Yes I have checked those threads, it seems like a common bug affecting many users randomly! I used the solution from here: https://stackoverflow.com/questions/30220771/recyclerview-inconsistency-detected-invalid-item-position and it seems solved the problem. – Om Infowave Developers Mar 16 '18 at 05:14
  • In one of the links DynamicMind mentioned in the comments, I found the suggestion to remove a call to `setStableIds(true)`. This fixed it for me! – Tina Jun 18 '21 at 00:03

0 Answers0