• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Constructor error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not defined a parameterized constructor which takes an int as argument.
 
Sheriff
Posts: 67665
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also be sure to follow established naming conventions. Class names should always start with an uppercase letter.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you are running the code that doesn't compile.
If that is the case read this:
https://coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication
 
Marshal
Posts: 76416
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic