• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cant "call" method?  RSS feed

 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So im having trouble with this code below. what im doing is experimenting with interfaces, packages and such. im not sure why when i "call" the method in addressMain it gives met this error:
"The method writeTo(String, String, String) in the type BookWriter is not applicable for the arguments () addressMain.java /adressBook/src/addressBook line 14 "


other class



and heres the interface!!


Any tips and such would be helpful. im really just messing around with java till i can get a better grasp on it! and im really sorry im going to comment my code as soon as i can remember to!


 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you see Line-13 in addressMain class- You are calling the method- writeTo(), but in the BookWriter class the method writeTo() takes 3 String parameters. So you are trying to invoke a non-existent method.
Either you add- writeTo() in the BookWriter class | Book interface OR change this book.writeTo() to pass 3 String parameters.
 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:If you see Line-13 in addressMain class- You are calling the method- writeTo(), but in the BookWriter class the method writeTo() takes 3 String parameters. So you are trying to invoke a non-existent method.
Either you add- writeTo() in the BookWriter class | Book interface OR change this book.writeTo() to pass 3 String parameters.


could you explain further or provide a link on passing the string parameters such as these or similar?
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Here's a link to the part of the Java tutorial about classes and objects which explains how to call a method: http://download.oracle.com/javase/tutorial/java/javaOO/arguments.html. You might well profit from reading the other sections of that tutorial as well.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to fill in a little explanation on one point: one reply correctly said "So you are trying to invoke a non-existent method. " In Java, different methods can have the same name but different numbers of parameters; in other words, you could define one method thus:

and another in the same class like:

These are completely separate methods that happen to have the same name. So, in your code, you were attempting to call a method that took no parameters, and (as the other poster said) that method does not exist. But it can be confusing to someone starting out, especially if they are used to languages where you cannot have two subprograms with the same name, regardless of what their parameters are.

The java compiler is helping out in this respect; it is telling you that the way you called it is not compatible with a definition that it found, and telling you what both of them are. This is very helpful when you're calling something that takes 6 or 8 parameters and you've gotten one of them wrong; inspecting the error message helps a lot figuring out what the problem is.

From an engineering standpoint, of course, it would be best if these completely separate methods did not do unrelated things; our human minds will understand the program best if those methods are CLOSELY related, since we use names to identify things and associate their function with their names, etc.

Hope that's some help.
rc
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!