aspose file tools*
The moose likes Beginning Java and the fly likes cannot be applied to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot be applied to" Watch "cannot be applied to" New topic
Author

cannot be applied to

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
I'm getting an error on line 243 "setLeft(TreeNode) in TreeNode cannot be applied to (ExprTree)" From what I understand What is sent in the parameter for setLeft method should be of type TreeNode so am I incorrect in thinking that I can call the constructor from within the same class to create a new node of type TreeNode?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

Dustin Schreader wrote:I'm getting an error on line 243 "setLeft(TreeNode) in TreeNode cannot be applied to (ExprTree)" From what I understand What is sent in the parameter for setLeft method should be of type TreeNode so am I incorrect in thinking that I can call the constructor from within the same class to create a new node of type TreeNode?


Well, yes. You don't need me to tell you that an ExprTree isn't a TreeNode -- the compiler has already told you that. So yes, you're incorrect, calling the ExprTree constructor doesn't result in an object of type TreeNode. It results in an ExprTree object, of course.
Anurag Malaviya
Greenhorn

Joined: Jul 01, 2009
Posts: 19
Hi Dustin

Its hard to know the complete logic of your program with this code, it would be better if you can post the code of setLeft(TreeNode) method
or may be an explanation of your Treenode class.

what i understand from this code is that you should pass the ROOT object that you are creating to the setLeft() method instead of Exptree object.

Regards
Anurag Malaviya
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
I was supposed to put a ExprTreeNode instead and now it works... It must be getting late... Thank you for the direction because it seemed to help.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
if ExprTreeNode extends TreeNode, then you won't get that compilation error. As ExprTreeNode IS - A TreeNode now.
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
I suppose I'm wondering if this is really the proper way to be doing this. ExprTreeNode is the ADT and the TreeNode is my interface. We're just learning trees and interfaces, so I guess what I should say is, should I be using ExprTreeNode's constructor or is it more correct to access the constructor through the interface TreeNode somehow. This is part of a lab and the code for the interface was already given so i'm not sure if I should be modifying it at all. Here is the interface.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot be applied to