Scanner NoSuchElementException

You have more than one Scanner that you close, which closes the underlying InputStream, therefore another Scanner can no longer read from the same InputStream and a NoSuchElementException results.

For console apps, use a single Scanner to read from System.in.


Since you print out the same message in all three places where an exception is caught, it is difficult to say with any certainty what is going on:

  • Use printStackTrace() to find out where the exception is happening

  • Don't catch Exception like that. Catch the exceptions that you are expecting and that your code is designed to handle. If you catch Exception you could end up catching all sorts of unexpected exceptions (NPE, end of file, etc) ... and incorrectly reporting them as "Invalid format".