• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing Tree Error.  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have an empty Tree(t) which is passed into my method, along with a String(s). I then check if the root (t.data) is empty, which it is. I then set the t.data to equal the String passed in. I have initialized my Tree so it can be empty, or a Tree can contain a String at the root and null either side.

But when I try and return I get this error code
Nameofpackage.Tree@e48e1b


Any ideas?
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Owen Martin wrote:But when I try and return I get this error code
Nameofpackage.Tree@e48e1b

That's not an error, that's the default return value for toString(). It is the full class name with package as you've already figured out, followed by an @ and the hash code in hexadecimal format.

If you override toString() you can make it print out whatever you want:
Of course this is not a good implementation, but you can basically return whatever you want. Usually you return something that is built using one or more of the fields. The data would seem a good candidate.
 
Owen Martin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Feel so stupid now, thanks very much that has been hassling me for a good while. Cheers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!