이유는 배열의 크기가 3인데 4번째 아이템에 접근했기 때문입니다. 아래를 보시면 이해가 가실 거예요.
str = "11/13(09-20)&&" // &로 끝나지 않는 문자열.
strSplit = str.split("&"); // ["11/13(09-20)", "'", ""]
str0=strSplit[0]; //11/13(09-20)
str1=strSplit[1]; // ""
str2=strSplit[2]; // ""
str3=strSplit[3]; // 존재하지 않음
위와 같은 경우 IndexOutOfBoundException이 발생합니다. 해결방법은 Exception를 캐치하거거나 Exception이 나지 않도록 방지하는 겁니다.
// Exception 캐치
try {
strSplit = str.split("&"); // ["11/13(09-20)", "'", ""]
str0=strSplit[0]; //11/13(09-20)
str1=strSplit[1]; // ""
str2=strSplit[2]; // ""
str3=strSplit[3]; // 존재하지 않음
} catch (IndexOutOfBoundException e) {
// 적절한 처리
}
// 에러방지
str = str + "&&&"; // 이렇게 &를 세개 더하면 어떤 경우에도 에러가 나지않겠죠.
strSplit = str.split("&");
str0=strSplit[0];
str1=strSplit[1];
str2=strSplit[2];
str3=strSplit[3];