aspose file tools*
The moose likes Beginning Java and the fly likes trying to call a method but cannot find symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trying to call a method but cannot find symbol" Watch "trying to call a method but cannot find symbol" New topic
Author

trying to call a method but cannot find symbol

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
This may be really easy to figure out but I guess i'm not understanding with the following code


I get an error cannot find symbol in the printInformation method. But the printInfo(); seems to work just fine in the print method second from the bottom.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You're trying to call a printInfo method on a String variable. Shouldn't this be a Customer ?


[My Blog]
All roads lead to JavaRanch
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
I want the method to print the customer info given the customer id number. So i'm trying to create a method that will print that info out.
maybe this helps

This method is from my other class: Customer
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes, but you didn't get what I'm trying to say

Look at "num.printInfo();". What is "num" ? It's a String. printInfo() is not a method of the String class. Where is that method ? In the Customer class ? Then you have to call it on a customer, not on a String.
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
Ok so I would want to write it like this?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
So now since it's not a string type anymore, how will it be able to print out the correct customer given a customer number (customerNum) string. This is the code from main.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

customerSearch should return a Customer, instead of returning a boolean. Then you can use the returned value to print the information. If the returned value is null, then the customerId does not exist.
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
So I think I understand the concept. but I still need the original customerSearch method because it is used by another method. So I would make a second customerSearchTwo and have it return Customer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: trying to call a method but cannot find symbol