index out of bounds exception java [duplicate]

我怕爱的太早我们不能终老 提交于 2019-11-28 12:38:10

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

ArrayList is empty. It does not contain any element.

Index: 0, Size: 0.

You are trying to access it.So you are getting IndexOutOfBoundsException.

if(r.size() == 0) && r.size() < pointer + 1)   //If ArrayList size is zero then simply return from method.
  return;

You are passing in an empty array. You should do some validation on the inputs

if (r == null || r.size()==0){
   throw new RuntimeException("Invalid ArrayList");
}

Your array size is 0, you should initialize it correctly in order to iterate it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!