nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

一、报错

nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

二、解决

https://blog.csdn.net/weixin_39274753/article/details/79709830

三、总结(引用上文的总结)

在往数据库添加数据需要判断数据库中是否已有记录,判断的返回结果通常是List。在List为空的情况下,调用其方法需要格外注意,例如:调用get()则会报下标越界的异常。

当然还可以联想到其他情况,当判断数组、集合为空后,注意不要取其中内容,不然就会报上述错误。

原文地址:https://www.cnblogs.com/peanut-zh/p/15063989.html