Получавам тази грешка 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)
Ето за системните функции: всеки път, когато добавям systemFunction на потребителя, той показва грешката или когато systemFunction colummn в базата данни е нула. Но когато настроя systemFunction = "" в базата данни, страницата се показва правилно, въпреки че без масив от системни функции очевидно ..
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";
}
}
Отговори:
-1 за отговор № 1Трябва да проверите systemFunctions
дали е нула и дали дължината му е по-голяма от 0:
if(systemFunctions!=null && systemFunctions.length>0){
...
}