【发布时间】:2014-02-05 06:48:43
【问题描述】:
通过复选框在数组中添加系统函数对象时,我遇到了这个 java.lang.indexoutofboundsexception 错误:
SEVERE: Servlet.service() for servlet spis threw exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at com.spis.dao.impl.CodesValueDaoImpl.getDescription(CodesValueDaoImpl.java:95)
at com.spis.bo.impl.CodesValueBoImpl.getDescription(CodesValueBoImpl.java:103)
at com.spis.controller.SystemUserController.viewPaged(SystemUserController.java:408)
at com.spis.controller.SystemUserController.systemUser(SystemUserController.java:48)
这是 systemFunctions:每当我将 systemFunction 添加到用户时,它都会显示错误,或者当数据库中的 systemFunction 列为空时。但是当我在数据库中设置 systemFunction=" " 时,页面显示正确,尽管显然没有 systemFunctions 数组..
String[] systemFunctions=(String[])request.getParameterValues("systemFunctions");
String appendedSysFunctions ="";
//Append system functions
if(systemFunctions!=null){
for(int i=0;i<systemFunctions.length;i++){
if(i==(systemFunctions.length-1)){
appendedSysFunctions+=systemFunctions[i];
}
else{
appendedSysFunctions+=systemFunctions[i] + ",";
}
}
}
另一个代码:
StringTokenizer st = new StringTokenizer(su.getAllowedSysFunc(), ",");
while (st.hasMoreTokens()){
appendedSystemFunc = appendedSystemFunc + codesValueMethods.getDescription
(3, st.nextToken());
if(st.hasMoreTokens()){
appendedSystemFunc = appendedSystemFunc + ", \n";
}
}
【问题讨论】:
-
systemFunctions没有元素。调试你的代码。 -
如果您以可读的方式格式化您的代码,这将非常有帮助 - 修复缩进,并在行内添加一些有用的空格。
-
另外,您向我们展示了
getDescription一点也不明显——哪一行引发了异常? (堆栈跟踪谈到了描述——你向我们展示的所有代码都是关于“系统函数”的,我们不知道这两者之间的关系是什么。) -
@JonSkeet 它在那里,我想,在第二个 sn-p 中。
codesValueMethods.getDescription(3, st.nextToken());虽然我认为这对我们没有帮助。相反,我认为问题出在ArrayList#get所在的位置。 -
@Radiodef:嗯,这就是 to
getDescription的调用(尽管我们不知道来自什么)。但是我们需要getDescription本身的代码。目前还不够。
标签: java indexoutofboundsexception