Results 1 to 10 of 10

Thread: Scanner Error

  1. #1

    Thread Starter
    Addicted Member Peter1's Avatar
    Join Date
    Aug 2002
    Posts
    166

    Resolved Scanner Error

    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.

    Code:
    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.

    Code:
    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
    Last edited by Peter1; Dec 3rd, 2004 at 05:07 AM.

  2. #2

    Thread Starter
    Addicted Member Peter1's Avatar
    Join Date
    Aug 2002
    Posts
    166
    :bump:

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Apparently my beta JDK version doesn't have any of the Scanner constructors...

    Will test as soon as I get the new version installed.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Addicted Member Peter1's Avatar
    Join Date
    Aug 2002
    Posts
    166
    Thanks.

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

  5. #5

    Thread Starter
    Addicted Member Peter1's Avatar
    Join Date
    Aug 2002
    Posts
    166

    Re: Scanner Error

    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.

  6. #6
    New Member
    Join Date
    Jan 2005
    Posts
    2

    Re: Scanner Error

    I aslo meet this trouble like you, can anyone help out of this?

  7. #7
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Scanner Error

    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.

  8. #8
    New Member
    Join Date
    Jan 2005
    Posts
    2

    Re: Scanner Error

    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!!!

  9. #9
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Scanner Error

    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?

  10. #10
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Scanner Error

    Do you know what JRE netbeans is using?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width