RecyclerView IndexOutOfBoundsException
2017-02-09 00:00
211 查看
一、错误信息:
二、问题原因:据说是这是Android-support-v7包中的bug。
三、解决方案:捕获这个异常,如让我们的程序崩溃;重写Wrapper,然后用setLayoutManager设置。
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
public WrapContentLinearLayoutManager(Context context) {
super(context);
}
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
参考网站:http://stackoverflow.com/questions/31759171/recyclerview-and-java-lang-indexoutofboundsexception-inconsistency-detected-in
1android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4505) |
2 android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4636) |
3 android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617) |
4 android.support.v7.widget.LayoutState.next(LayoutState.java:100) |
5 android.support.v7.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1538) |
6 android.support.v7.widget.StaggeredGridLayoutManager.scrollBy(StaggeredGridLayoutManager.java:2060) |
7 android.support.v7.widget.StaggeredGridLayoutManager.scrollVerticallyBy(StaggeredGridLayoutManager.java:1980) |
8 android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4061) |
9 android.view.Choreographer$CallbackRecord.run(Choreographer.java:780) |
10 android.view.Choreographer.doCallbacks(Choreographer.java:593) |
11 android.view.Choreographer.doFrame(Choreographer.java:561) |
12 android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:766) |
13 android.os.Handler.handleCallback(Handler.java:733) |
14 android.os.Handler.dispatchMessage(Handler.java:95) |
15 android.os.Looper.loop(Looper.java:136) |
16 android.app.ActivityThread.main(ActivityThread.java:5314) |
17 java.lang.reflect.Method.invokeNative(Native Method) |
18 java.lang.reflect.Method.invoke(Method.java:515) |
19 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) |
20 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680) |
21 dalvik.system.NativeStart.main(Native Method) |
三、解决方案:捕获这个异常,如让我们的程序崩溃;重写Wrapper,然后用setLayoutManager设置。
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
public WrapContentLinearLayoutManager(Context context) {
super(context);
}
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
参考网站:http://stackoverflow.com/questions/31759171/recyclerview-and-java-lang-indexoutofboundsexception-inconsistency-detected-in
相关文章推荐
- RecyclerView 的IndexOutOfBoundsException: Inconsistency detected异常解决办法
- 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30
- RecyclerView IndexOutOfBoundsException 引出的RecyclerView 的使用方法总结
- RecyclerView 删除元素后,点击报 IndexOutOfBoundsException 解决方法
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- Support v-7 recycler view 出现IndexOutOfBoundsException: Inconsistency detected.异常解决办法。
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView 出现java.lang.IndexOutOfBoundsException: Index: 13, Size: 12 问题解决
- 成功解决RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案(转)
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- 【转载】Android RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter
- RecyclerView内部BUG: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item positio
- RecyclerView:java.lang.IndexOutOfBoundsException: Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- Android问题集-RecyclerView--java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position 解决方案
- RecyclerView自带bug,切换数据出现IndexOutOfBoundsException
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position …