设为首页 加入收藏

TOP

Java中list.get(index)报错
2014-11-24 01:42:54 来源: 作者: 【 】 浏览:1
Tags:Java list.get index 报错

1、list.get(index)中的index为负值异常

严重:Exception occurred during processing request:-1

java.lang.ArrayIndexOutOfBoundsException:-1


原因:if(null != list.get(list.size()-1) && null != list.get(list.size()-1).getValue())

{

}


分析:当list.size() = 0时,list.size()-1 = -1,而list.get(index)中的index大于等于0,故会抛出数组越界异常。


2、list.get(0)赋值异常

严重:Exception occurred during processing request:Index:0,Size:0

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


原因:if(list.size() == 0)

{

maxLabel = list.get(0).getLabel();

minLabel = list.get(0).getLabel();

}


分析:当list.size = 0时,说明list为空,list.get(0).getLabel()就会抛出异常。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇数组排序 sort 下一篇字符串水题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: