이 예외에 대한 모든 질문을 보았습니다. 배열 인덱스가 0부터 시작하고 크기가 1 인 경우 인덱스 0에만 액세스 할 수 있다는 것을 알고 있습니다.이 논리를 알고 있지만 다음 코드를 수정할 수 없습니다.인덱스 1, 크기 1 예외
private static Map<String, Map<String, List<String>>> executions = new HashMap<String, Map<String, List<String>>>();
public static String readExecution(String jobName, String deviceName, int executionNumber) {
String result = null;
Map<String, List<String>> jobExecutions = executions.get(jobName);
if (jobExecutions != null) {
List<String> executionPerDevice = jobExecutions.get(deviceName);
result = executionPerDevice.get(executionNumber); // ERROR
}
return result;
}
편집 : Fildor의 comment.execution 번호의 대답은 1
디버그를 :이 숫자가 어쨌든 executionPerDevice 크기에 맞는 경우 확인해야하므로 실행 번호는 인수로 외부에서 전달됩니다. 'executionNumber'가 "1"이라고 말하고 싶습니다. 만약 당신이 1로 번호 매기기를 시작한다면,이'result = executionPerDevice.get (executionNumber-1);을 만들고, 또한 몇몇 nullchecks를 할 것입니다. – Fildor
executionPerDevice의 크기를 확인하고 executionNumber와 비교할 수 있습니다. –
IndexOutOfBound 예외는 매우 쉬운 예외입니다. 존재하지 않는 것을 얻기 위해 노력하고 있습니다. 코드를 가져 와서 왜 값이 없는지 알아 내려면 코드를 디버깅하십시오. – john