标签:
最近写一个listView中多个listItem布局时,convertView缓存及使用,类似微信的聊天界面的listView,报了一个异常:
11-25 15:51:49.076: E/InputEventReceiver(22971): Exception dispatching input event.
11-25 15:51:49.128: E/AndroidRuntime(22971): FATAL EXCEPTION: main
11-25 15:51:49.128: E/AndroidRuntime(22971): java.lang.ArrayIndexOutOfBoundsException: length=2; index=3
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6771)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5265)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3232)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3558)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.View.dispatchTouchEvent(View.java:7315)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2253)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1950)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2259)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1964)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2259)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1964)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2259)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1964)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2259)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1964)
11-25 15:51:49.128: E/AndroidRuntime(22971): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1970)
11-25 15:51:49.128: E/AndroidRuntime(22971): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1420)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.app.Activity.dispatchTouchEvent(Activity.java:2444)
11-25 15:51:49.128: E/AndroidRuntime(22971): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1918)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.View.dispatchPointerEvent(View.java:7506)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3680)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3605)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4875)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4835)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4991)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4959)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5013)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.Choreographer.doCallbacks(Choreographer.java:579)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.Choreographer.doFrame(Choreographer.java:546)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.os.Handler.handleCallback(Handler.java:800)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.os.Handler.dispatchMessage(Handler.java:100)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.os.Looper.loop(Looper.java:194)
11-25 15:51:49.128: E/AndroidRuntime(22971): at android.app.ActivityThread.main(ActivityThread.java:5398)
11-25 15:51:49.128: E/AndroidRuntime(22971): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 15:51:49.128: E/AndroidRuntime(22971): at java.lang.reflect.Method.invoke(Method.java:525)
11-25 15:51:49.128: E/AndroidRuntime(22971): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-25 15:51:49.128: E/AndroidRuntime(22971): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
11-25 15:51:49.128: E/AndroidRuntime(22971): at dalvik.system.NativeStart.main(Native Method)
11-25 15:51:49.182: E/AppErrorDialog(590): Failed to get ILowStorageHandle instance
代码如下:
我的GlobalConstant.java中定义了type:
琢磨了半天,我的getViewTypeCount()返回的是2,getItemViewType获取的是type值,同样是2个,为什么会报这个错误,在网上搜索到了一个关键信息:
从stackoverflow上看到的回答如下:
The item view type you are returning from getItemViewType() is >= getViewTypeCount().
确实是这个问题,我的type定义了2种,而且是从3开始。。。
讲GlobalConstant.java中的type值分别改为0,1,就解决了该问题:
BaseAdapter的ArrayIndexOutOfBoundsException
标签:
原文地址:http://www.cnblogs.com/exmyth/p/4549800.html