가 나는 NullPointerException이 던져 수 있다고 생각합니다. nextToken의 부호()를 검사
여기서
public String nextToken() {
/*
* If next position already computed in hasMoreElements() and
* delimiters have changed between the computation and this invocation,
* then use the computed value.
*/
currentPosition = (newPosition >= 0 && !delimsChanged) ?
newPosition : skipDelimiters(currentPosition);
/* Reset these anyway */
delimsChanged = false;
newPosition = -1;
if (currentPosition >= maxPosition)
throw new NoSuchElementException();
int start = currentPosition;
currentPosition = scanToken(currentPosition);
return str.substring(start, currentPosition);
}
, skipDelimiters 메소드의 호출() NullPointerException이 던져.
private int skipDelimiters(int startPos) {
if (delimiters == null)
throw new NullPointerException();
int position = startPos;
while (!retDelims && position < maxPosition) {
if (!hasSurrogates) {
char c = str.charAt(position);
if ((c > maxDelimCodePoint) || (delimiters.indexOf(c) < 0))
break;
position++;
} else {
int c = str.codePointAt(position);
if ((c > maxDelimCodePoint) || !isDelimiter(c)) {
break;
}
position += Character.charCount(c);
}
}
return position;
}
생성자에 null 문자열을 전달하지 않습니까? countTokens()는 무엇을 반환합니까? – Reno
StringTokenzier의 생성자에? 그렇게 생각하지 않는다면 생성자 자체에서 NullPointerException이 발생하고 이것이 내 경우는 아닙니다. – duduamar