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 trialAaron Lawson
1,282 PointsI keep getting an error in my console....and can't figure out where I went wrong in the video
./com/teamtreehouse/Treet.java:13: error: incompatible types: Date cannot be converted to String
mCreationDate = creationDate;
^
./com/teamtreehouse/Treet.java:25: error: incompatible types: String cannot be converted to Date
return mCreationDate;
^
2 errors
Could someone help me out with what I did wrong...?
Treet.java package com.teamtreehouse;
import java.util.Date;
public class Treet { private String mAuthor; private String mDescription; private String mCreationDate;
public Treet(String author, String description, Date creationDate) { mAuthor = author; mDescription = description; mCreationDate = creationDate; }
public String getAuthor() { return mAuthor; }
public String getDescription() { return mDescription; }
public Date getCreationDate() { return mCreationDate; }
}
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? Simply tweet about Java and use" + "the hashtag #treet. I'll use your tweet in a new" + "@treehouse course about data structures.", new Date(1421849732000L) ); System.out.printf("This is a new Treet: %s %n", treet);
} }
4 Answers
Lorenzo Ferrante
2,064 PointsmCreationDate is using the Date class not the String class. Just change private String mCreationDate; to private Date mCreationDate; You could also do private Date mCreationDate = new Date(); It will default to today's date, without having to insert the epoch-millisecond long number. It worked for me.
Lorenzo Ferrante
2,064 PointsSomehow it didn't respect my editor's formatting, making it look like a big ugly block. Sorry.
Alexandra Silcox
24,486 PointsAnswer in the wrong place, sorry about that.
I had the exact same issue, turns out that I tried to set mCreationDate as a String, not Date.
So in Treet.java
Instead of: private String mCreationDate;
It needs to be: private Date mCreationDate;
Hope this helps!
Aaron Lawson
1,282 PointsAwesome, sorry it took a while to say thanks! Ive been on military orders but Im gonna try this out. Thanks so much for your help
Benjamin Gooch
20,367 PointsAaron,
Out of curiosity, what branch do you serve in? I'm Army. They don't have any MOS's that teach programming so this is a hobby of mine. I was wondering what your motivation was for taking the java course.
When I get out (some day) I hope to have bolstered my skills enough to create a game development startup.
Back on topic, Yeah, I did the exact same thing too, when I paused the video and tried it on my own before Craig shows how to do it. I didn't know there was a Date().
Alexandra Silcox
24,486 PointsAlexandra Silcox
24,486 PointsI had the exact same issue, turns out that I tried to set mCreationDate as a String, not Date.
So in Treet.java
Instead of: private String mCreationDate;
It needs to be: private Date mCreationDate;
Hope this helps!