所以,我不明白为什么会出现这个错误:
04-06 17:51:10.252:E / AndroidRuntime(10745):致命异常:主要 04-06 17:51:10.252:E / AndroidRuntime(10745):流程: com.stm.classlife,PID:10745 04-06 17:51:10.252: E / AndroidRuntime(10745):java.lang.ArrayIndexOutOfBoundsException: 长度= 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(母语 方法)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
有人知道如何解决它吗?
答案 0 :(得分:12)
在崩溃日志中,这是相关的一行:
android.widget.AbsListView $ RecycleBin.addScrapView(AbsListView.java:6588)
if (mViewTypeCount == 1) {
mCurrentScrap.add(scrap);
} else {
mScrapViews[viewType].add(scrap);
}
基本上,当您在屏幕外滚动列表视图项并且回收器尝试回收它时会发生这种情况。 android.widget.Adapter#getItemViewType(int)
返回的此视图的视图类型正在抛出您的java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
。
请参阅android.widget.Adapter#getItemViewType(int):
注意:整数必须在0到getViewTypeCount() - 1的范围内。
我遇到了同样的问题。检查getItemViewType(int)
的覆盖方法,并确保返回连续的零索引号。由于您的getViewTypeCount()
方法返回2,因此项类型的常量必须为0和1。