Search code examples
javajava.util.scannernosuchelementexception

How java.util.NoSuchElementException (basic program)


java.util.NoSuchElementException problem... I used two scanners

scanbud()

and

scabudrad()

Solution

  • The reason is here:

    scanbudRad.close();     
    

    you are using multiple instances of the scanner, _BUT as soon as you closes a scanner, that instance close under the hood too the input stream which is shared between all other remaining instances... after that, trying to read /get something from an scanner object with a InputStream closed throws the exception.