RecyclerView: java.lang.IndexOutOfBoundsException: Inconsistencia detectada. Posición de artículo no válida

He empezado a informar de este accidente en Crashlytics. No tengo ni idea de cómo reproducirlo, pero todo parece ser el código interno de la RecyclerView . Creo que esto viene de un RecyclerView que tengo que nunca cambia realmente. El usuario puede actualizarlo, pero luego todos los elementos se reemplazan y notifyDataSetChanged se llama.

 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) 

2 Solutions collect form web for “RecyclerView: java.lang.IndexOutOfBoundsException: Inconsistencia detectada. Posición de artículo no válida”

Tengo el mismo problema con este problema, estoy muy cansado de buscar y resolverlo. Pero he encontrado respuesta a la resolución y las excepciones no han sido rechazadas de nuevo.

 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(); } } } 

Espero que esta respuesta sea resolver su problema.

Cree su propio 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); } } 

Cómo configurar CustomLinearLayoutManager en RecyclerView .

 CustomLinearLayoutManager customLinearLayoutManager= new HPLinearLayoutManager(mContext); recyclerView.setLayoutManager(customLinearLayoutManager); 

Espero que esto le ahorrará tiempo.

  • Margen entre elementos en reciclado ver Android
  • ¿Es posible arrastrar el elemento fuera de RecyclerView?
  • Cómo agregar un scroller rápido al RecyclerView
  • Comportamiento parecido a un buscador en RecyclerView
  • Recuperando onBindViewHolder al desplazarse por la vista Recycler
  • Fade out / fade en TextView basado en desplazamiento
  • (Smooth) ScrollToPosition no funciona correctamente con RecyclerView
  • Problemas con la implementación del modo de acción contextual en fragmento recyclerview
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.