Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired Getting There Object Inheritance

Wan Nor Adzahari Wan Tajuddin
Wan Nor Adzahari Wan Tajuddin
2,438 Points

Why am I getting a null?

When I run my code I kept getting This is a new Treet: Treet: "null" - @null"

I've checked my code and I can't seem to find what's wrong with it? Can you find the mistake?

https://w.trhou.se/q5he0hhugs

2 Answers

Fahad Mutair
Fahad Mutair
10,359 Points

you have error here i just notice that

Treet.java
public Treet(String author, String description, Date creationDate) {
  mAuthor = author;
  mDescription=description;
  mCreationDate=creationDate ;
}
Wan Nor Adzahari Wan Tajuddin
Wan Nor Adzahari Wan Tajuddin
2,438 Points

Oh yes. That's the issue. I made it the other way around! Thank you!

Fahad Mutair
Fahad Mutair
10,359 Points

you forgot to put @Override annotation on toString method

Treet.java
@Override
public String toString() {
  return "Treet: \"" + mDescription + "\" - @" + mAuthor;
}
Wan Nor Adzahari Wan Tajuddin
Wan Nor Adzahari Wan Tajuddin
2,438 Points

But as according to the video, Craig's codes works fine even before he put @Override