Using try(Scanner scan = new Scanner(System.in)) { }
is causing
Exception in thread "main" java.util.NoSuchElementException
When I try to debug it says that
Variable information not available, source compiled without -g option.
and shows the below code
public Scanner(InputStream source) {
this(new InputStreamReader(source), WHITESPACE_PATTERN);
}
One of my methods that uses this line:
protected String loginName(){
String username;
String password;
try (Scanner scan = new Scanner(System.in)) { // This line is causing the error.
System.out.print("Enter Username: ");
username = scan.next();
System.out.print("Enter Password: ");
password = scan.next();
}
if(getUsernamesList().contains(username))
if(password.equals(getPasswordsList().get(getUsernamesList().indexOf(username)))) return username;
else return "-1";
else return "-1";
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…