So, I don't understand why appear this error:
04-06 17:51:10.252: E/AndroidRuntime(10745): FATAL EXCEPTION: main 04-06 17:51:10.252: E/AndroidRuntime(10745): Process: com.stm.classlife, PID: 10745 04-06 17:51:10.252: E/AndroidRuntime(10745): java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6588) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.widget.ListView.layoutChildren(ListView.java:1632) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.widget.AbsListView.onTouchMove(AbsListView.java:3763) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3632) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.View.dispatchTouchEvent(View.java:8471) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2399) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2092) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106) 04-06 17:51:10.252: E/AndroidRuntime(10745): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369) 04-06 17:51:10.252: E/AndroidRuntime(10745): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.app.Activity.dispatchTouchEvent(Activity.java:2742) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268) 04-06 17:51:10.252: E/AndroidRuntime(10745): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.View.dispatchPointerEvent(View.java:8666) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5868) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5920) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.Choreographer.doCallbacks(Choreographer.java:580) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.Choreographer.doFrame(Choreographer.java:548) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.os.Handler.handleCallback(Handler.java:739) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.os.Handler.dispatchMessage(Handler.java:95) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.os.Looper.loop(Looper.java:135) 04-06 17:51:10.252: E/AndroidRuntime(10745): at android.app.ActivityThread.main(ActivityThread.java:5254) 04-06 17:51:10.252: E/AndroidRuntime(10745): at java.lang.reflect.Method.invoke(Native Method) 04-06 17:51:10.252: E/AndroidRuntime(10745): at java.lang.reflect.Meth
Anybody know how to fix it?
From your crash logs here is the relevant line:
android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6588)
if (mViewTypeCount == 1) {
mCurrentScrap.add(scrap);
} else {
mScrapViews[viewType].add(scrap);
}
Essentially this happens when you scroll a list view item off-screen and the recycler tries to reclaim it. View type for this view, as returned by android.widget.Adapter#getItemViewType(int)
, is throwing your java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
.
See android.widget.Adapter#getItemViewType(int):
Note: Integers must be in the range 0 to getViewTypeCount() - 1.
I had the same problem. Check your override method for getItemViewType(int)
, and ensure that you're returning consecutive zero-index numbers. Since your getViewTypeCount()
method is returning 2, then your constants for item type must be 0 and 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With