• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructor error  RSS feed

 
Jeremy Plate
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a binary search tree in Java and having some trouble figuring out what I have done. I have posted my code that seems to be problematic and the errors generated are at the bottom. Thanks.




---------------------------------------------------------------------------------------------------------






--------------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------





-----------------------------------------------------------------------------------------------




--------------------------------------------------------------------------------------------



Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor take2(int) is undefined
The method input(int, node.BSTNode, boolean) is undefined for the type take2
The constructor take2(int) is undefined
The method input(int, node.BSTNode, boolean) is undefined for the type take2
The method pre(node.BSTNode) is undefined for the type take2
The method in(node.BSTNode) is undefined for the type take2
The method post(node.BSTNode) is undefined for the type take2
The method pre(node.BSTNode) is undefined for the type take2
The method in(node.BSTNode) is undefined for the type take2
The method post(node.BSTNode) is undefined for the type take2
The method last(node.BSTNode) is undefined for the type take2

at take2.main(take2.java:11)
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have not defined a parameterized constructor which takes an int as argument.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also be sure to follow established naming conventions. Class names should always start with an uppercase letter.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, there are a lot of compile problems. In the future, compile early and often and avoid a situation like this.

Let's start with the first: "The constructor take2(int) is undefined"

This line:

needs a constructor that takes an int. Right now you only have the default constructor which takes not arguments.

"The method input(int, node.BSTNode, boolean) is undefined for the type take2"
This code:

Need a method with the signature of (int, node.BSTNode, boolean) but it doesn't exist.

And so on. Basically fix one error and recompile and fix another.

Also, class names start with a capital letter by convention, so Take2, Input, Left, Post, Pre.
 
Jeremy Plate
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Node does exist, there is more code that does not seem problematic. Node is below.



 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Plate wrote:Node does exist, there is more code that does not seem problematic. Node is below.

Yes, but the error says "input" method does not exist in class "take2".
You really have to decode the error messages to get to a solution.
It will come as you practice more.

And as people said in previous posts, follow the naming convention.
variable name should start with lowercase.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you are running the code that doesn't compile.
If that is the case read this:
http://www.coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please don't double‑space your code; that makes it harder to read. There is something wrong with a constructor as long as that for input. That should be divided up into several method calls. Give all the methods private access or mark them final.

Please show us the inheritance of your classes. There is something peculiar about input extends balancing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!