[Solved] Loop is infinitly looping or IndexOutOfBoundsException: Index =4, Size =2


You are getting IndexOutOfBoundsException on restrictedAreaArrayList,
You are adding imageInfos to
restrictedAreaArrayList

with

restrictedAreaArrayList.add(i,imageInfos);

ith index may not exist in restrictedAreaArrayList you can just add it

restrictedAreaArrayList.add(imageInfos)

Or if you want to preserve the order then make restrictedAreaArrayList’s size equal to imageInfosArrayList
you can do that by creating it with

restrictedAreaArrayList = new ArrayList<ImageInfos>(imageInfosArrayList.size());

Or

you can call

restrictedAreaArrayList.ensureCapacity(imageInfosArrayList.size())

to make sure it has same capacity as imageInfosArrayList

solved Loop is infinitly looping or IndexOutOfBoundsException: Index =4, Size =2