Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android index out of bounds error with no application code in stack trace

This is the stack trace:

java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)     at java.util.ArrayList.get(ArrayList.java:311)     at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)     at android.widget.ListView.dispatchDrawWithExcessScroll_Default(ListView.java:3354)     at android.widget.ListView.dispatchDraw(ListView.java:3054)     at android.view.View.draw(View.java:6936)     at android.widget.AbsListView.draw(AbsListView.java:3022)     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.View.draw(View.java:6936)     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.View.draw(View.java:6936)     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)     at android.view.View.draw(View.java:6936)     at android.widget.FrameLayout.draw(FrameLayout.java:357)     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)     at android.view.ViewRoot.draw(ViewRoot.java:1527)     at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)     at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)     at android.os.Handler.dispatchMessage(Handler.java:99)     at android.os.Looper.loop(Looper.java:123)     at android.app.ActivityThread.main(ActivityThread.java:3687)     at java.lang.reflect.Method.invokeNative(Native Method)     at java.lang.reflect.Method.invoke(Method.java:507)     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)     at dalvik.system.NativeStart.main(Native Method) 

I have absolutely no idea how to reproduce this error. I've tried randomly click at every ListView on my application and was never able to reproduce this error.

This only happened after the application was shipped to the market. I've never seen this error before.

The worst part is that it has no code from my application so I don't even know what the user was doing when this happened.

Did anyone ever see this kind of error?

Does anyone have a clue where to start fixing this?

like image 980
Draiken Avatar asked Nov 24 '11 11:11

Draiken


2 Answers

I also ran into this same exception on a Nexus 5 running Lollipop. It would occur if I:

  • unplugged the device while a list is shown
  • let the device fall asleep
  • plugged the device back in, causing the list contents to be refreshed

Adding a dummy footer didn't fix it, it just changed the error to Invalid index 1, size is 1 :) ...but thanks to @AlexD I had a clue of where to look for workarounds.

In my case calling list.setFooterDividersEnabled(false) after the ListView is created successfully prevents the crash from occurring.

like image 185
Lorne Laliberte Avatar answered Oct 16 '22 16:10

Lorne Laliberte


I've got the same error sometime when listview is empty. After looking at the source code I've found the line that crashes:

return mFooterViewInfos.get(adjPosition - adapterCount).isSelectable 

As you can see there's no check if mFooterViewInfos is empty, so my workaround for this issue is just adding a dummy footer:

list.addFooterView(new View(context, null, false)); 
like image 29
AlexD Avatar answered Oct 16 '22 17:10

AlexD