IndexOutOfBoundsException异常与列表视图视图、异常、列表、IndexOutOfBoundsException

2023-09-13 02:13:25 作者:「舊綪鉃鳦」

我刚刚得到一个奇怪的IndexOutOfBoundsException异常,我似乎无法重现。这似乎是我的相关listactivity:

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)

我想这可能与我如何添加/删除我footerview。这里是code为:

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:\nCurrent page size: " + cursor.getCount()%10 + "\nCurrent category: " + currentCategory + "\nPage: " + 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);
    }
}

翻翻源$ C ​​$ C,错误似乎在这行抛出的headerviewlistadapter的getview方式:

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?

推荐答案

期待通过谷歌网站的code后,我看到了很多不同类型的初始化工作,并接入到mHeaderViewInfos,但我不实际看到的东西被添加到它。它可能会受益于扔在一些调试点,并通过跟踪它。祝你好运!

After looking through the code on the google site, I see a lot of different types of initializations and accesses to the mHeaderViewInfos, but I don't actually see anything being added to it. It might benefit to throw in some debug points and trace it through. Good luck!