StickyHeaders icon indicating copy to clipboard operation
StickyHeaders copied to clipboard

IndexOutOfBoundsException: onBindItemViewHolder

Open rusmichal opened this issue 7 years ago • 1 comments

I found one issue

@Override
    public void onBindItemViewHolder(ItemViewHolder viewHolder, int sectionIndex, int itemIndex, int itemType) {
        int sectionPosition = includeHeader ? sectionIndex - 1 : sectionIndex;
        switch (itemType) {
            case ITEM_HEADER:
               ...
                break;
            case ITEM_TILE:
                initTile((FeedViewHolder) viewHolder, feedDataProviders.get(sectionPosition).getTileViewModelList().get(itemIndex), sectionPosition);
                break;
            case ITEM_FOOTER:
                ...
                break;
            default:
                break;
        }
    }

Where feedDataProviders is List<FeedDataProvider>. FeedDataProvider has list of custom objects TileViewModel.

I got IndexOutOfBoundsException: Invalid index 0, size is 0 in line initTile() because getTileViewModelList() return empty list and itemIndex is 0. I think if getNumberOfItemsInSection return 0 then is should not called the onBindItemViewHolder right?

@Override
    public int getNumberOfItemsInSection(int sectionIndex) {
        if((includeHeader && sectionIndex == 0) || (includeFooter && sectionIndex == getNumberOfSections() - 1)) {
            return 1;
        }
        return feedDataProviders.get(includeHeader ? sectionIndex - 1 : sectionIndex).getTileViewModelList().size();
    }

rusmichal avatar Aug 11 '16 07:08 rusmichal

Good point. I'll look into fixing this. Thanks!

ShamylZakariya avatar Aug 19 '16 18:08 ShamylZakariya