Exception in thread \"main\" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:604)
You are trying to access the first element lstpp.get(0)
of an empty array. Just add an element to your array and check for !lstpp.isEmpty()
before accessing an element
Use if(index.length() < 0)
for Integer
or
Use if(index.equals(null)
for String
This error happens because your list lstpp
is empty (Nothing at index 0). So either there is a bug in your getResult()
function, or the empty list is normal and you need to handle this case (By checking the size of the list before, or catching the exception).
You do not have any elements in the list so can't access the first element.
You want to get an element from an empty array. That's why the Size: 0
from the exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
So you cant do lstpp.get(0)
until you fill the array.
lstpp
is empty. You cant access the first element of an empty list.
In general, you can check if size > index
.
In your case, you need to check if lstpp
is empty. (you can use !lstpp.isEmpty()
)