이상한 예외 코드가 나타납니다. 다음과 같이StringIndexOutOfBoundsException : 문자열 인덱스가 범위를 벗어났습니다. 0
내가 사용하려고 코드는 다음과 같습니다
do
{
//blah blah actions.
System.out.print("\nEnter another rental (y/n): ");
another = Keyboard.nextLine();
}
while (Character.toUpperCase(another.charAt(0)) == 'Y');
오류 코드는 다음과 같습니다
는Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:686)
at Store.main(Store.java:57)
선 (57)는 시작이다 "동안 ...".
제발 도와주세요.
또 하나는 "Y"로 인스턴스화됩니다. "YES"로 인스턴스화 된 경우에도 동일한 오류가 발생했습니다. – Chente
Chente -이 오류는 'another'가 빈 문자열 인 경우에만 ** 발생할 수 있습니다. 어설 션을보다 면밀하게 (디버거로 이상적으로 볼 수 있도록 이상적으로) 확인하거나 Itay의 제안을 구현하고 문제가 어떻게 사라지는 지 확인하십시오. –