我已经开始在Crashlytics上报道这次坠机事件。我不知道如何复制它,但它似乎都是回收视图
内部的代码。我认为这来自于我的<代码>回收视图</代码>它从未真正改变过。用户可以刷新它,但随后会替换所有项,并调用notifyDataSetChanged
。
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 5(offset:5).state:7
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4041)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3999)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1892)
at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:419)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1301)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:534)
at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:156)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2365)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2709)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1877)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1653)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:907)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2325)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2031)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6233)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5296)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(NativeStart.java)
创建自己的LinearLayoutManager。
CustomLinearLayoutManager.java
public class CustomLinearLayoutManager extends LinearLayoutManager {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
public CustomLinearLayoutManager(Context context) {
super(context);
}
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}
如何在 RecyclerView 上设置 CustomLinearLayoutManager。
CustomLinearLayoutManager customLinearLayoutManager= new HPLinearLayoutManager(mContext);
recyclerView.setLayoutManager(customLinearLayoutManager);
希望这会节省你的时间。
我一直在面对这个问题,我已经厌倦了寻找解决方案。但我已经找到了一个解决这个问题的答案,没有任何例外被再次抛出。
public class MyLinearLayoutManager extends LinearLayoutManager {
public MyLinearLayoutManager(Context context) {
super(context);
}
public MyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public MyLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
//override this method and implement code as below
try {
super.onLayoutChildren(recycler, state);
} catch (Exception e) {
e.printStackTrace();
}
} }
我希望这个答案能解决你的问题。
你们能帮我做这个吗 这是我添加片段的代码 但当我从添加的片段中按back时,我出现了这个错误,我的应用程序崩溃了。 为什么会这样?请帮忙。我正在使用两个片段。产品列表fragent和产品详细信息片段
我在我的应用程序中使用带有的。因为我已经从加载了,并且在后台调用服务之后,尝试通过
我有一个“回收者”视图,它在除三星以外的所有设备上都能完美运行。在三星上,我明白了 JAVAlang.IndexOutOfBoundsException:检测到不一致。视图保持架适配器位置无效视图保持架 当我从另一个活动的“回收者”视图返回片段时。 适配器代码: 例外: 我该怎么解决这个问题?
我们的 QA 检测到一个错误:发生了以下与 RecyclerView 相关的崩溃:' Java . lang . indexoutofboundsexception:检测到不一致。无效的项目位置2(偏移量:2)。状态:3 一个残酷的解决方法可能是在异常发生时捕获它,并从头开始重新创建RecycleverView实例,以避免处于损坏状态。 但是,如果可能的话,我想更好地理解这个问题(也许从根源上修复
这是我的应用,问题出在哪里 我希望我的物品能像这个应用一样合身 我正在使用带有的。我的问题是,当其中一个项目具有更长的文本时,您可以在图像中看到网格项的高度不相同。我正在从Firebase加载数据,并在列表具有数据时通知。我尝试了一切,但找不到一个解决方案来自动适应项目,如第二张图片所附。有什么帮助吗? 这是我的recyclerview项目布局