File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Error passing values to a method - any help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error passing values to a method - any help!!" Watch "Error passing values to a method - any help!!" New topic
Author

Error passing values to a method - any help!!

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm currently writing a simple test application for a couple of classes. The problem arises when I try to pass values to an add method in the CustomerList class. These values are read from user input as a String and an int value. However, the add method in the CustomerList class is then trying to add these new values to an array within the class.

Basically, how do I send the String and int values to the add method, when the add method is as follows,




My code for the test class is currently as follows,



When I try to run the class I get the following error,



Any help or advice greatly appreciated!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Are you sure the line throwing the compiler error is actually on the screen?
CR
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

Many thanks for the reply. Within the main class, the error is being thrown in the following line,



I think the problem is that the method 'add' in the CustomerList class refers to (Customer newItem), whereas the main class reads in both a customer name and number. How do I convert the values read in as a String and an int, in the main class, to a Customer object, which I can then pass to the add method as required in the CustomerList class?

Many thanks!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Oh, sorry, I think I have found the line you were referring to.
Find out wherever you are calling that add() method from; there may be several places, and work out what you are passing as a parameter. In one case you would appear to be passing a String rather than what your method requires.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Yes, you are passing a String. But your method signature requires a Customer . . .

That is what the error message means.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
You don't mean to pass (new Customer(name, number)), do you???
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

That's brilliant. It works now. The best solutions are always the simplest, and usually staring you right in the face. Thank you so much for your help.

One last quick question though. If I read from one file, loans.txt, and then write the data to a data file, loans.data, any idea how I transfer the information from the loans.data file to the loans.txt file when I run the main class?

I know I can just write the new dat straight to the loans.txt file, but I always thought that was particularly bad practice.

Any ideas or help appreciated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error passing values to a method - any help!!