• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using a scanner parameter  RSS feed

 
Mark Captain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!