• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems using the Scanner class  RSS feed

 
K Donegan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making a small game for an assignment which involves the user entering numbers from standard input. We were told to do this using the Scanner class, so in my main method I have:


This compiles and works fine but I want to use this same Scanner object, referenced by scan, in a method contained in a different class called Contestant. So my method looks like this:


However, the javac compiler is giving me some error when I try and make this method. What am I doing wrong? How could I access the same scanner in my Contestant class as the one I have created
in the main() method? I hope I have been clear enough as to what I am trying to do! Any help is much appreciated.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you showed the code that is calling this method, and the compiler error.
 
K Donegan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, the method isn't ever really called because the class won't compile. Here is the error which the compiler gives me:

Contestant.java:16: cannot find symbol
symbol : class Scanner
location: class Contestant
public void makeMove( Board board, Scanner scan ) {
 
K Donegan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, figured it out. I'm an idiot forgot the import statement.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!