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)
Andreas_5
0
Newbie Poster
Recommended Answers
Jump to PostThere'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
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
rproffitt
commented:
"Number 5... is alive! Malfunction! Need input!"
+15
Andreas_5
commented:
I haven't closed any of the inputs and it worked!
+0
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.