Results 1 to 10 of 10

Thread: Scanner Error

Threaded View

  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.

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