While coding a random program about how Convenient the program was for the user , I use Scanner, and its .nextInt(); to ask the user to rate the program's Convenience: 275.Scanner scan = new Scanner(System.in); 276.System.out.println("Rate the convenience of this program by typing 1 to 5..."); 277.System.out.println("1. *"); 278.System.out.println("2. * *"); 279.System.out.println("3. * * *"); 280.System.out.println("4. * * * *"); 281.System.out.println("5. * * * * *"); 282.int inp; 283.inp = scan.nextInt(); I get the error: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at expences.Main.main(Main.java:283)
Jump to Post
There's nothing wrong in the code you posted, so the problem lies somewhere else. Without the whole code and the actual input there's nothing more we can do.
But in general the NoSuchElementException is thrown when the input stream has been closed, so cannot supply any more input for scanning. …
All 3 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.