I just got a strange indexoutofboundsexception that I can't seem to reproduce. It seems to be related to my listactivity:
java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
at java.util.ArrayList.get(ArrayList.java:311)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:229)
at android.widget.AbsListView.obtainView(AbsListView.java:1410)
at android.widget.ListView.makeAndAddView(ListView.java:1802)
at android.widget.ListView.fillDown(ListView.java:727)
at android.widget.ListView.fillSpecific(ListView.java:1359)
at android.widget.ListView.layoutChildren(ListView.java:1633)
at android.widget.AbsListView.onLayout(AbsListView.java:1263)
at android.view.View.layout(View.java:7088)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.widget.FrameLayout.onLayout(FrameLayout.java:334)
at android.view.View.layout(View.java:7088)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1056)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1752)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
I'm thinking it might be related to how I add/remove my footerview. Here is the code for that:
private void setLoadMoreFooter() {
resumeProgressBarAnimation(progressbar);
if (getListView().getFooterViewsCount() != 0 || currentCategory == null) {
try {
getListView().removeFooterView(footerView);
} catch (ClassCastException e) {
}
}
cursor = getVouchersFromDatabase();
Log.d(TAG, "Determining FOOTER status:
Current page size: " + cursor.getCount()%10 + "
Current category: " + currentCategory + "
Page: " + currentCategory.getPage());
// Add footer if there are 10 vouchers on the current page
if (cursor.getCount()%10 == 0 && currentCategory != null) {
getListView().addFooterView(footerView, null, true);
}
else if (currentCategory.getPage() >= 2 && cursor.getCount()%10 != 0) {
getListView().addFooterView(footerView, null, false);
}
}
Looking through the source code, the error seems to be thrown in the headerviewlistadapter's getview method at this line:
return mHeaderViewInfos.get(position).view;
Does anyone know what the cause of this might be?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…