Skip to content
Advertisement

Reading from File – Error “Exception in thread “main” java.util.NoSuchElementException: No line found”

I am writing a program that reads from a file titled “grades.txt” and displays the student’s name, three grades, and the average of those three grades.

The text file looks like this:

JavaScript

Here is the code. I am able to read from the file and output everything correctly.

JavaScript

However, I keep getting this error and I am not sure why:

JavaScript

From the research I’ve done, I believe it has something to do with going from nextLine to nextDouble, and the n being stuck in the keyboard buffer.

Or maybe I’m not using hasNext right?

How can I fix the error?

Advertisement

Answer

remove this line

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement