• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing Tree Error.

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Feel so stupid now, thanks very much that has been hassling me for a good while. Cheers.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic