• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Overloaded Constructor "Cannot resolve symbol"  RSS feed

 
Justin Swartsel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From within another class "BinaryTree" I'm testing if an object "BinaryNode" is null, and if it is, initialize it using a constructor. My problem is, if i initialize it with the default constructor "BinaryNode()" it works, however if I use the overloaded constructor "BinaryNode(int x)" it doesnt. It gives me a cannot resolve symbol. Is my problem with access? Or is it a memory issue in Java?

Here is the code for both classes, the problem is in bold:

BinaryTree class:


BinaryNode class:

 
Justin Swartsel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow. I'm stupid. I figured out that when you have a void return type in front of a constructor it will do that to ya.

So, now that I know that, why is it the case?
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have constructors for BinaryNode, you have methods that happen to have the same name as the class. Remove the return value "void" and you'll be okay.
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off the top of my head, I'd say you are probably not managing "x" in this situation.

You haven't supplied a copy of the call that creates the error, so I assumed that you mean to simply replace your bold type with your description.

If that is true, then you are using X as an argument of type BinaryNode and X as parameter as type int.

Double check this and let me know if it is still giving you an error. If so, please supply the code that is not correct.
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow. two quick answers in the time it took me to ask another question.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my first answer: If you have a return value, you don't have a constructor, you have a method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!