Results 1 to 8 of 8
Thread: Scanner error message
- 08-28-2010, 01:47 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 17
- Rep Power
- 0
Scanner error message
Hey, I was making a program that uses the scanner class but I got a weird error. I narrowed the code down and I found the source, but I don't know how to fix it. I get the error when I try to run the program, compiling it gives me no error. My code:
Error message:Java Code:import java.util.Scanner; public class UserInput { public static void main(String[] args) { Scanner myInput = new Scanner(System.in); int myNumber; myNumber = myInput.nextInt(); } }
I am using TextPad 5.3.1 and this development kit:Java Code:Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1461) at java.util.Scanner.nextInt(Scanner.java:2091) at java.util.Scanner.nextInt(Scanner.java:2050) at UserInput.main(UserInput.java:6) Tool completed with exit code 1
Java SE Downloads - Sun Developer Network (SDN)
I'm new to Java so please try to keep the answers well explained.
Thanks for the help.
-
I get no such error when I compile and run your program.
All the volunteers here strive to give the best answers that they can. If something isn't clear, then just ask.I'm new to Java so please try to keep the answers well explained.
Thanks for the help.
Best of luck.
- 08-28-2010, 01:59 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
There must've been a non-digit (or not a minus sign) in the input buffer; the OP must've accidentally typed something.
kind regards,
Jos
- 08-28-2010, 02:05 PM #4
Member
- Join Date
- Aug 2010
- Posts
- 17
- Rep Power
- 0
- 08-28-2010, 02:11 PM #5
What OS are you on?
How are you executing the program? From command prompt or from inside an IDE?
- 08-28-2010, 02:17 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
- 08-28-2010, 07:49 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 17
- Rep Power
- 0
I'm on Windows Vista Home Premium SP 2 (unfortunately).
I'm executing the program from an IDE (TextPad 5.3.1), using java.exe.
Though, I think I fixed it ... it looks like I didn't setup TextPad properly. I tried a few things but it wouldn't work so I changed to Eclipse and it now works fine. I did not reinstall JDK so I'm guessing that wasn't the problem. It would still be nice to know what the error message means though, so that I know what I'm dealing with if I get it in the future. Any ideas?Last edited by plm-pusik; 08-28-2010 at 07:52 PM.
- 08-28-2010, 08:39 PM #8
Have you looked at the API doc for the method you are using?know what the error message means
Here's a simple program that gets the error:
Java Code:String input = "1 3"; Scanner sc = new Scanner(input); while(true) { int x = sc.nextInt(); System.out.println("x=" + x); } /* x=1 x=3 Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1461) at java.util.Scanner.nextInt(Scanner.java:2091) at java.util.Scanner.nextInt(Scanner.java:2050) at TestCode1.main(TestCode1.java:35) */Last edited by Norm; 08-28-2010 at 08:51 PM.
Similar Threads
-
Error Message ..
By Hamodi18 in forum New To JavaReplies: 15Last Post: 07-11-2010, 03:31 AM -
Error Message????
By Cubba27 in forum New To JavaReplies: 11Last Post: 11-21-2009, 02:46 PM -
Error Message in JBuilder
By RavenNevarmore in forum New To JavaReplies: 4Last Post: 10-08-2008, 06:53 AM -
java error message
By baileyr in forum New To JavaReplies: 2Last Post: 01-23-2008, 03:47 AM -
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 02:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks