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 trialDemauri Portis
4,809 Points[SOLVED]mCreationDate cannot find symbol
Alright, now let's order the blog post's creation date chronologically, oldest first.
NOTE: The app where this class is being used ensures that no two blog posts are posted at the same time, so you do not need to worry about any edge cases.
I've looked at other forum posts of this similar code but at different stages in the course. I've tried exactly what they've done but yet still can't pass the challenge. Not understanding why stuck.mCreationDate cannot find symbol when passed into the compareTo argument when I'm still within the class with the private field. Any suggestion? Maybe a different approach, doesn't necessarily say I have to return this information, just order it.
package com.example;
import java.util.Date;
public class BlogPost implements Comparable {
private String mAuthor;
private String mTitle;
private String mBody;
private String mCategory;
private Date mCreationDate;
public BlogPost(String author, String title, String body, String category, Date creationDate) {
mAuthor = author;
mTitle = title;
mBody = body;
mCategory = category;
mCreationDate = creationDate;
}
@Override
public int compareTo(Object other) {
Object stuck = (BlogPost) other;
if(equals(other)) {
return 0;
}
// WHERE I FOUND MY MISTAKEEEEEEE
int dateCmp = mCreationDate.compareTo(stuck.mCreationDate);
if (dateCmp == 0) {
return dateCmp;
}
// THE DOUBLE RETURN STATEMENT SEEMS A BIT POINTLESS BUT IT WORKED.
return dateCmp;
}
public String[] getWords() {
return mBody.split("\\s+");
}
public String getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
public String getBody() {
return mBody;
}
public String getCategory() {
return mCategory;
}
public Date getCreationDate() {
return mCreationDate;
}
}
2 Answers
qasimalbaqali
17,839 PointsMind sharing how did you solve it?
Jordan George
9,926 PointsThe other return statement isn't pointless. It is there if dateCmp doesn't equal 0.
amathiaitishar
13,229 Pointsamathiaitishar
13,229 Pointsif you still hittin your head on the wall with this challenge, you might check this link: https://teamtreehouse.com/forum/how-do-i-do-this-15