IntelliJ Java IDE
The moose likes Beginning Java and the fly likes Using a scanner parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Using a scanner parameter" Watch "Using a scanner parameter" New topic
Author

Using a scanner parameter

Mark Captain
Ranch Hand

Joined: Nov 01, 2011
Posts: 30
Hi, I need to use a method with a Scanner as a parameter that is



What I have to do is call method in my main method to open on a .txt file and i cannot find a way for my code to work when i try to put the file to open inside like so



i am getting the error "The method loadBusStops(Scanner) in the type BusManager is not applicable for the arguments (String"

I understand why it is saying it is a string and that it my file to open needs to by of the "Scanner type". But how would I do this?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3143
This:


says that when you call loadBusStops, you will pass it a Scanner. It seems that you know that, given that your subject is "Using a scanner parameter".

Does this:

Look like you're passing a Scanner to that method? That is, do you think "bus-stops.txt" is a Scanner?

You need to do one of two things:

1) Pass a Scanner when you call loadBusStops(), as the method declaration says you will. This means you have to construct the Scanner with an appropriate File, Readable, or InputStream first, and then pass it to loadBusStops().

OR

2) Change loadBusStops() to take a String parameter. Then, inside the method, you construct the Scanner with an appropriate File, Readable, or InputStream for the file whose name you received.

 
IntelliJ Java IDE
 
subject: Using a scanner parameter
 
Threads others viewed
Scanning/Storing a String that the user enters?
Java Interpreter: Parsar Program
I want to use an add screen to add infromation to a hashmap, but cant get the add button to work
Having troubles with a complex program, need help with an illegal start of type error.
ERROR - "system cannot find the file specified"
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture