• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol error  RSS feed

 
Greenhorn
Posts: 13
Chrome Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot find symbol

symbol: method calculateTotalCompensation(double)
location: variable Salesperson1 of type Salesperson1

thus error is on line 39 and 46

 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On this line

The variable name you chose is the same as the class name. This is legal but it's very bad form.  By convention, variable and method names in Java start with a lowercase letter. That helps you distinguish them from class, interface, and enum type names. When you use "Salesperson1" as a variable name, it makes the reader work much harder to figure out whether you're referring the variable or the class.

On line 32, you are attempting to invoke Salesperson1.calculateTotalCompensation(sales).  That's a method call, except there is no such method defined in your Salesperson1 class. That's what "Symbol not found" means. The "symbol" being referred to is the name "calculateTotalCompensation"
 
Jonathan Mckulsky
Greenhorn
Posts: 13
Chrome Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 39 and 34 corrected but line 32 is still giving me problems with the symbol not found. I'm not sure how to correct it?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you tell someone to reach into your pocket and that person says to you, "How do I do that, you don't have any pockets!" you probably want to go and put on an article of clothing that does have a pocket, right?

In the same way, if you tell Java to call a method and Java says, "How do I do that, your program doesn't have such a method!" what do you think you should do?

Do you know how to define methods in Java?
 
Jonathan Mckulsky
Greenhorn
Posts: 13
Chrome Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would i create a method for calculateTotalCompensation? or a method for salesperson?
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:On line 32, you are attempting to invoke Salesperson1.calculateTotalCompensation(sales).  That's a method call, except there is no such method defined in your Salesperson1 class. That's what "Symbol not found" means. The "symbol" being referred to is the name "calculateTotalCompensation"

Here you are being told what method is missing.
 
Jonathan Mckulsky
Greenhorn
Posts: 13
Chrome Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am kinda self taught and am having a hard time learning this so I need it spelled out to me. I understand that some people can tell whats what but I have literally never done this before. So any help is greatly appreciated, i need to be tutored through this whole process.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then perhaps you should first go look at the Tutorial that I cited earlier, on how to define methods. Please remember, we're all volunteers here. If someone is willing to go the extra mile to tutor you step-by-step, that's fine. That's not normally what happens in these forums though. People just come here for tips and hints or further information that they can't find in more in-depth references like online tutorials or books.
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By all means, check out the link provided. Some great stuff in there.

When you see something like
It is telling you that there should be a method named "calculateTotalCompensation" in your "Salesperson1" class and that it should have exactly one argument that is the same type as your "sales" variable.

Additionally, you have to determine if you declare the method as being "static" or not. If you see a method being called like this:
then it is an instance method, i.e. not static. If it is being called like
it is a static method. Note that you should look up "static" in the links provided to get a better understanding.

Then you need to declare the return type of the method(). If you don't need to return any data then use "void". If you do need to return data then your design or requirements will dictate what return type to use. Sometimes the return type can be inferred by looking to see how the method is being used, but not always.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!