0
이 문제는 StringTokenizer를 이해하지 못한다는 확신이 들지만, 어디서나이 답변을 찾을 수는 없습니다. 이 오류가 발생하는 이유는 무엇입니까?왜 NoSuchElementException이 발생합니까?
import java.io.*;
import java.util.StringTokenizer;
import java.util.Scanner;
public class NHLDemo {
public static void main(String[] args) throws FileNotFoundException{
File file = new File("nhlstats");
Scanner inputFile = new Scanner(file);
PlayerRecord pr;
NHLStats list = new NHLStats();
while(inputFile.hasNext())
{
String line = inputFile.next();
StringTokenizer token = new StringTokenizer(line, "\t");
while(token.hasMoreTokens()){
System.out.print(token.nextToken());
System.out.print(token.nextToken());
String name = token.nextToken();
String position = token.nextToken();
String team = token.nextToken();
int gp = Integer.parseInt(token.nextToken());
int g = Integer.parseInt(token.nextToken());
int a = Integer.parseInt(token.nextToken());
int pim = Integer.parseInt(token.nextToken());
int sog = Integer.parseInt(token.nextToken());
int gwg = Integer.parseInt(token.nextToken());
pr = new PlayerRecord(name, position, team, gp, g, a, pim, sog, gwg);
list.add(pr);
}
}
list.enumerate();
}
}
I는 각 라인에 토큰이 동일한 양을 가진 특정 파일로부터 데이터를 판독하고
(예. 세인트루이스 RW TB 48 17 43 14 112 2
Stamkos C TB 48 29 28 32 157 2
오베 츠킨 RW WSH 48 32 24 36 220 4
크로스비 PIT C 36 15 41 16 124 1 등)