5

I'm really hoping someone can help me out with this one. I've been stuck on it forever. Occasionally, when someone is using my app, it'll force close with this exception:

java.lang.ArrayIndexOutOfBoundsException
    at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:3572)
    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2487)
    at android.widget.AbsListView.onTouchEvent(AbsListView.java:2001)
    at android.widget.ListView.onTouchEvent(ListView.java:3234)
    at android.view.View.dispatchTouchEvent(View.java:3709)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4568)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)

However, I cannot figure out why. It's relatively rare, non-reproducable, and the stacktrace is completely unhelpful because it doesn't include any of my code.

Is it a bug in Android itself?

1
  • Probably not. Post the code for your ListView adapter. And does your adapter contain a Collection that you might be modifying somewhere else in the app? Commented Jun 10, 2010 at 19:20

2 Answers 2

11

What version of Android are you running? From what I can tell your Adapter is returning the wrong count from getViewTypeCount() (or you are changing the view type count dynamically which is a big mistake.)

Sign up to request clarification or add additional context in comments.

3 Comments

Not sure which version this particular exception came from, but I've had it happen to me on 2.1. I'm not overriding getViewTypeCount() or getItemViewType() at all, so I'm not sure how this could happen
Actually, I was wrong. I'm an idiot. I was overriding them, and returning the incorrect view type count. Thanks
How can tell the Adapter is returning the wrong count from getViewTypeCount() ?
5

In addition to what Romain said, it seems to be important that the largest view type is smaller than the view type count.

I had two view types defined (for what ever reason) with 1 and 2 and returned 2 in getViewTypeCount() which gave me the same exception as above. Re-indexing the types to 0 and 1 fixed the issue.

1 Comment

You're a life saver! I had no idea the index used for constants as view type can cause this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.