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 Getting There Class Review

James Adamski
James Adamski
3,027 Points

Why is my Date value recognized as a string?

The value I have for mCreationDate in this exercise is being interpreted as a String.

To my eyes every point of the code labels the type as a Date. Can you see what's causing the error?

File Example.java


import java.util.Date; import com.teamtreehouse.Treet;

public class Example {

public static void main(String[] args){

Treet treet = new Treet("craigdennis",
                       "Want to be famous? Tweet about Java with #treet!",
                       "tweet",
                        new Date(1421849732000L)
                       );
System.out.printf("This is a new Treet: %s %n", treet);  

}

}

File Treet.java


public class Treet {

private String mAuthor; private String mTitle; private String mDescription; private Date mCreationDate = new Date();

public Treet ( String author, String title, String description, Date creationDate){

mAuthor = author;
mDescription = creationDate;
mTitle = title;
mCreationDate = creationDate;

}

public String getAuthor(){ return mAuthor; } public String getmDescription() { return mDescription; } public String getmTitle() { return mTitle; } public Date mCreationDate() { return mCreationDate; }

}

2 Answers

Linda de Haan
Linda de Haan
12,413 Points

Do you mean this line in your Treet constructor:

mDescription = creationDate;

Because that should say this:

mDescription = description;

I tried your code in my IDE with the right description line in the constructor and it works fine.