• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Scanner woes

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76415
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic