Results 1 to 5 of 5

Thread: Scanner error

  1. #1
    kprime is offline Member
    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0

    Default Scanner error

    Hi,

    I'm having some problem writing a simple scanner to read input from the keyboard. I'm getting some compiler errors that I don't understand. A majority of the errors deal with a line of code that I don't see in my code. One error reads:
    .\Scanner.java:4: error: ';' expected
    private char array[][] tokenstring =

    The next error says something about "reached the end of file while parsing". Another error says that the constructor in class Scanner takes no arguments?

    My code is below. What's weird is that it works if I change the import statement to import java.util.Scanner. The same code also works if I put the file in a different folder. Can someone tell my why I'm getting these errors? Thank you.

    :

    Java Code:
    import java.util.*;
    
    public class TestScanner
    {
    	public static void main(String[] args)
    	{	
    		Scanner in = new Scanner(System.in);
    		String s;
    		while (!(s = in.nextLine()).equals("-1"))
    		{
    			System.out.println(s);
    		}
    	}
    }

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Scanner error

    Are you sure you are compiling the right java class? The TestScanner class should compiled with no error.

  3. #3
    kprime is offline Member
    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0

    Default Re: Scanner error

    Hi,

    Thank you for the reply. Yes, I'm pretty sure that I'm compiling the right code. When I make changes to the code (basically removing the code with the Scanner class) it compiles just fine.

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Scanner error

    Well, you must import the java.util.Scanner to take input using the Scanner class. Did you have another class named Scanner on your current project?

  5. #5
    kprime is offline Member
    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0

    Default Re: Scanner error

    Ah! Thank you very much! That was indeed the problem. I have all my Java programs for testing purposes in a single folder and one of them was named Scanner.

    Thank you for your help, it was driving me nuts .

Similar Threads

  1. help with the Scanner
    By HelloWorld1234 in forum New To Java
    Replies: 2
    Last Post: 02-03-2013, 01:05 AM
  2. How to use Scanner ?
    By sandeep43 in forum New To Java
    Replies: 7
    Last Post: 08-10-2011, 01:29 PM
  3. Scanner to int?
    By N00Bie in forum New To Java
    Replies: 6
    Last Post: 02-12-2011, 12:14 AM
  4. Scanner error message
    By plm-pusik in forum New To Java
    Replies: 7
    Last Post: 08-28-2010, 08:39 PM
  5. need help with scanner
    By whiterex in forum New To Java
    Replies: 1
    Last Post: 04-22-2008, 01:41 PM

Posting Permissions

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