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
.
More Related Contents:
- Exception in thread “main” java.util.NoSuchElementException
- Exception in thread “main” java.io.FileNotFoundException: Error
- I am new in using ArrayLists. Array Out of Bounds, Array seems to be empty, but have been adding Strings to it already
- How can I read a text file in Android?
- java.util.NoSuchElementException: No line found
- What is an OutOfMemoryError and how do I debug and fix it
- Scanner vs. StringTokenizer vs. String.Split
- How to define custom exception class in Java, the easiest way?
- Why doesn’t Java allow generic subclasses of Throwable?
- How can I write custom Exceptions?
- How do you assert that a certain exception is thrown in JUnit tests?
- How do I increase the number of displayed lines of a Java stack trace dump?
- Handling Java crypto exceptions
- nextDouble() throws an InputMismatchException when I enter a double
- JDBC driver throws “ResultSet Closed” exception on empty ResultSet
- How can i handle it with scanner (java)?
- Java: Infinite loop using Scanner in.hasNextInt()
- Scanner only reads file name and nothing else
- How to parse number string containing commas into an integer in java?
- Scanner only reads first word instead of line
- What is difference between Errors and Exceptions? [duplicate]
- java.net.MalformedURLException: no protocol
- Java using scanner enter key pressed
- PKIX path building failed in Java application
- How can I detect when an Exception’s been thrown globally in Java?
- Exception without stack trace in Java
- String index out of bounds exception java
- Catching an exception that is nested into another exception
- Is it a bad idea to use printStackTrace() for caugt Exceptions?
- The local variable might not have been initialized – Detect unchecked exception throw within a method