【发布时间】:2015-04-17 16:00:30
【问题描述】:
Scanner s = new Scanner(new File("src/mail_list"));
while (s.hasNextLine()){
String line1 = s.nextLine();
if (line1.startsWith("Users")){
line1 = s.nextLine();
while (!(line1 = s.nextLine()).isEmpty()) {
String arr[] = line1.split(" ", 4);
users.add(new User(arr[0],arr[1],arr[2],arr[3]));
}
}
if (line1.startsWith("Lists")){
line1 = s.nextLine();
while (!(line1 = s.nextLine()).isEmpty()) { //exception here
String arr1[] = line1.split(" ", 2);
ArrayList<String> tmp = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(arr1[1]);
while (st.hasMoreTokens()) {
tmp.add(st.nextToken());
}
list.add(new List((arr1[0]), tmp));
}
}
}
/*-testfile-start*/
Keyword: Users
username1 Name1 Surname1 email1
username2 Name2 Surname2 email2
Keyword: Lists
list_name username1 username2 ...
/*-testfile-end*/
我正在使用上面的代码从上面的测试文件模式中排序。基本上这意味着如果我遇到关键字“用户”,我必须添加有关用户的上述信息。
我在代码中标记了异常出现的位置。关于如何应对它的任何想法?
【问题讨论】:
-
什么异常?请发布堆栈跟踪。
-
线程“主”java.util.NoSuchElementException 中的异常:找不到行。
-
嗯..很清楚了,请调试您的代码以了解为什么找不到行。
-
我正在调试...如果我发现问题我会关闭线程...
标签: java nosuchelementexception