Tuesday, 10 September 2013

Java Scanner Error : Exception in thread "main" java.util.NoSuchElementException: No line found

Java Scanner Error : Exception in thread "main"
java.util.NoSuchElementException: No line found

I am trying to get user input but I keep getting the error: No Line Found
The line number is referencing "input = fileS.nextLine();" as the source
of the error
System.out.print("Is this table a simple table? Please check document to
confirm, If YES please Enter Y If NO please Enter N \n");
Scanner fileS = new Scanner(System.in);
input = fileS.nextLine();
input = input.trim();
input = input.toLowerCase();
tableCount ++;
fileS.close();
That is my code, I understand that if I used fileS.hasNextLine() it would
avoid this error But this skips the user input all together.
What am I missing here?
The scanner is in a public function
Thanks in advance!

No comments:

Post a Comment