1

where I scroll RecyclerView got problem on this code

this one from RecyclerView.Adapter

return items.get(position) != null ? VIEW_ITEM : VIEW_PROG;

and this one from activity

lLayout = new GridLayoutManager(MyActivity.this, 2);
        rView.setVisibility(View.VISIBLE);
        rView.setHasFixedSize(true);
        rView.setLayoutManager(lLayout);
        lLayout.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                switch(rcAdapter.getItemViewType(position)){
                    case RecyclerViewAdapter.VIEW_ITEM:
                        return 1;
                    case RecyclerViewAdapter.VIEW_PROG:
                        return 2;
                    default:
                        return -1;
                }
            }
        });

Got Exception :

java.lang.IndexOutOfBoundsException: Invalid index 49, size is 0 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

help me how to fixed this thank you

Nikunj
  • 3,937
  • 19
  • 33
Fajar
  • 31
  • 4
  • 5
    Possible duplicate of [Why does ArrayIndexOutOfBoundsException occur and how to avoid it in Android?](https://stackoverflow.com/questions/4958235/why-does-arrayindexoutofboundsexception-occur-and-how-to-avoid-it-in-android) – Hemant Parmar Mar 20 '18 at 10:27
  • 2
    It says there are **no items in your array list and you're trying to access the 49th item**. – SripadRaj Mar 20 '18 at 10:30
  • 2
    post your adapter class – Jyoti JK Mar 20 '18 at 10:32

0 Answers0