检测到不一致使用RecyclerView的notifyItemRemoved(position)方法时抛出异常

时间:2018-03-16 04:12:24

标签: android android-recyclerview recycler-adapter

我有一个RecyclerView,其中包含多种类型的项目视图,其中包含TextView,ImageView和Exoplayer。

每当用户想要从列表中删除某个项目时,我只需从ArrayList删除该项目,然后调用notifyItemRemoved(p)适配器的RecyclerView方法。

到目前为止工作正常,但最近应用程序开始崩溃Inconsistency detected Exception

以下是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

以下是我正在使用的删除方法:

feedDetailList.remove(position);
feedAdapter.notifyItemRemoved(position);

0 个答案:

没有答案