• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner woes  RSS feed

 
Justin Core
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having issues trying to use the scanner properly within my program.
I keep receiving this error:
scan cannot be resolved to a variable

I can add another Scanner in the main method and resolve this issue but I do not want two instances of a scanner in my code because I will be redirecting from a data file to test the program.

Thus I ask you how can I fix this issue? Thank you.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That has nothing to do with Scanners. What it is, is that you are declaring the Scanner object in one method, so it goes out of scope when you get to the other method, and is not accessible.

And why are you doing everything in a static context?
 
Justin Core
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, Stupid mistake on my part.
Thank you. I wasn't positive why I was using static for both methods.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!