-1

I am running my project which is on recyclerview and I am getting an error while scrolling my list.

When I am scrolling down my list I am getting error in recycelrview and my application closes.

See the errors below:

2019-03-25 22:40:45.464 746-801/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
2019-03-25 22:40:45.467 746-801/? E/ANDR-PERF-REQUEST: Failed to set timer
2019-03-25 22:40:45.922 29813-29813/com.example.narayanstore E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.narayanstore, PID: 29813
    java.lang.IndexOutOfBoundsException: Index: 50, Size: 50
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.example.narayanstore.RecyclerViewAdapter.onBindViewHolder(RecyclerViewAdapter.java:47)
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • here is my Recyclerviewadpater class..code...I have 3 arraylist and each list have 50 items. – Devender saini Mar 25 '19 at 17:19
  • fyi, the array position starts from 0.. as you said you have 50 items.. The log cat error shows you are accessing item #51.. which does not exists.. So maybe do something in your for loop like this : `for int i = 0; i < yourlist.size() - 1; i++` – Masoom Badi Mar 25 '19 at 17:42
  • 1
    and please attach code... note just the comment here is my code.. that doesn't help. – Masoom Badi Mar 25 '19 at 17:50

1 Answers1

0

Usually

IndexOutOfBoundException

will happen if you are trying to access data which is currently not in adapter.

So you need to check whether any data changes in adapter by calling the following method.

notifyDataSetChanged()

Magudesh
  • 419
  • 5
  • 13
  • There is difference between ArrayIndexOutOfBoundsException and IndexOutOfBoundsException. See here https://stackoverflow.com/questions/34266174/difference-between-arrayindexoutofboundsexception-and-indexoutofboundsexception – Magudesh Mar 25 '19 at 17:46
  • Index out of bound exception : Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out of range. see the logcat and comment he made.. – Masoom Badi Mar 25 '19 at 17:49