PDA

Click to See Complete Forum and Search --> : Scanner Error


Peter1
Nov 23rd, 2004, 03:30 PM
Hello.

I am using Netbeans 4.0 Beta 2 with JDK 1.5. With this simple, short code I am generating an error that I can't seem to figure out.


import java.util.*;

public class Main
{
public static void main (String [] args)
{
Scanner input = new Scanner(System.in);
String myName = input.next();
System.out.println(myName);
}
}


It builds fine, however when I run the program it generates this error message.


Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:817)
at java.util.Scanner.next(Scanner.java:1317)
at Main.main(Main.java:8)
Java Result: 1


Has anyone encountered this. I have reinstalled Netbeans and the JDK several times, but it still doesn't work.

Thanks for any help.

Pete

Peter1
Nov 27th, 2004, 02:11 PM
:bump:

CornedBee
Nov 28th, 2004, 01:55 PM
Apparently my beta JDK version doesn't have any of the Scanner constructors...

Will test as soon as I get the new version installed.

Peter1
Nov 28th, 2004, 02:31 PM
Thanks.

I've installed the Netbeans Release Candidate, but it still doesn't work. So I don't think its that.

Peter1
Dec 3rd, 2004, 04:06 AM
Turns out it probably was Netbeans. I installed wordpad and used that to compile the program and it works fine. Switch over to Netbeans and it still doesn't work.

ansi
Jan 15th, 2005, 03:20 AM
I aslo meet this trouble like you, can anyone help out of this? :cry:

System_Error
Jan 15th, 2005, 07:17 AM
This compiles and runs fine for me. I know serveral people have had weird errors while running netbeans.

ansi, are you running netbeans also?


Note: You might could try input.close(); after teh System.outprintln() statement. Don't know if this will work or not.

ansi
Jan 17th, 2005, 07:32 AM
Of course, I use Netbeans 4.0 with jdk1.5.0.
I have try your idea but i still don't work.
The most interesting thing is it's ok with another editor program even if the command prompt. Does Netbeans conflict with my computer????

I hope you can help us!!!

System_Error
Jan 17th, 2005, 08:24 AM
Netbeans is known to have some weird problems. At my school, my teacher tried to compile a simple hello world app, but it came up some weird stuff that wasn't even in the program.

Personally, I would just switch to a different IDE, but if you insist on keeping it, I guess you coud stay with it.

So it works with other editors using the command line....

Try using a different IDE like JCreator, BlueJ, or something simple that will let you compile and run the program. If you try this, let me know the results. If it compiles and runs fine, then something's up with netbeans.

I think I might download netbeans and try it out.


NOTE: DID YOU DOWNLOAD AND INSTALL THE NETBEANS VERSION THAT WAS BUNDLED WITH THE JDK?

System_Error
Jan 17th, 2005, 08:36 AM
Do you know what JRE netbeans is using?