Java 在队列列表中添加时发生IndexOutOfBoundException
其中queueList是队列的ArrayListJava 在队列列表中添加时发生IndexOutOfBoundException,java,arrays,list,arraylist,indexoutofboundsexception,Java,Arrays,List,Arraylist,Indexoutofboundsexception,其中queueList是队列的ArrayListqueueArrayListqueueList 问题:在队列列表中添加时,索引为2,列表大小为1,因此,IndexOutOfBoundException在第行抛出 this.queueList.add(queueIndex,queue) 避免这种情况的最佳方法是什么?在Advanced中,感谢为避免IndexOutOfBounds问题,请在执行操作之前检查要使用的实际大小和索引 private void removeQueue(Queue queu
queue
ArrayListqueueList
问题:在队列列表中添加时,索引为2,列表大小为1,因此,
IndexOutOfBoundException
在第行抛出this.queueList.add(queueIndex,queue)
避免这种情况的最佳方法是什么?在Advanced中,感谢为避免IndexOutOfBounds问题,请在执行操作之前检查要使用的实际大小和索引
private void removeQueue(Queue queue)
{
queue.setTodoDeleted(false);
if ( queueIndex != -1) {
this.queueList.add(queueIndex , queue);
mItemManger.closeAllItems();
}
}
queueIndex
来自哪里?它应该遵循队列
大小…索引为2,列表大小为1,您正在尝试获取不存在的元素谢谢,文卡特使用它工作没有引发异常。@Swift您应该尝试找出队列索引大于实际大小的原因。
if ( queueList.size()>queueIndex)
{
this.queueList.add(queueIndex , queue);
}
// Add else part if needed