2 Replies Latest reply: Jan 24, 2013 5:35 PM by Jörg RSS

    error: cannot find symbol // Scanner kybd = new Scanner(System.in);

    987016
      Hello Java Masters,

      I wrote method code that prompts user to enter positive integer. When I add scanner into method file I get this:


      methodLibrary.java:153: error: cannot find symbol
      Scanner kybd = new Scanner(System.in);
      ^
      symbol: class Scanner
      location: class methodLibrary
      methodLibrary.java:153: error: cannot find symbol
      Scanner kybd = new Scanner(System.in);
      ^
      symbol: class Scanner
      location: class methodLibrary
      2 errors

      ----jGRASP wedge2: exit code for process is 1.
      ----jGRASP: operation complete.

      When I put new Scanner into LibraryTest.java it does not recognize my scanner:

      methodLibrary.java:163: error: cannot find symbol
      n = kybd.nextInt();

      NOTE:I use two libraries: method library(extends) and public class LibraryTest

      METHOD CODE:

      public static int getPosInt( )
                
      {
                     
                     
                     
                     
      int userInput = 0;
                     int n;

                     while(userInput<0)
                     {
                     System.out.print("Please enter positive integer: ");
                     n = kybd.nextInt();
                     
                     userInput = n;
                     }
      return(userInput);
      }

      CODE:
      //test getPosInt( )
                returnVal = getPosInt( );
                System.out.println(returnVal + " is a positive integer.");

      Any clues what am I doing wrong? Thank you in advance,

      Bart(newbie)