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 Organizing Data Comparable

William Doring
PLUS
William Doring
Courses Plus Student 4,388 Points

java comparable page seems off

I am working on task 3 of 3 at https://teamtreehouse.com/library/java-data-structures/organizing-data/comparable

My code had an error but it won't let me return to my code. It offers to get help, recheck work, or go to task one.

Additionally when I scroll down these three buttons are cascaded vertically, this seems inconsistent with the other pages.

com/example/BlogPost.java
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;
  }

  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;
  }
  public int compareTo(Object obj){
    BlogPost bp = (BlogPost) obj;

    if(equals(obj))
      return 0;
    return compareTo(obj);
    /*
  return compareTo(obj);
  */
  }
}

3 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there William,

I know that they recently updated the UI of treehouse so they might still be ironing kinks on that end, when it only gives the option to go to task 1 that is because treehouse checks every task portion each time one is completed. So say you pass 1 of 3, but you edit something in 3 of 3 that allows 1 to no longer pass, it would ask you to go back to task one because it was no longer passing.

I can see that you commented out the code that returns 1, when the grading code couldn't find that, it tried to kick it back to task one to complete it, thinking that's where the error was (computers are still unfortunately only as smart as we program their logic to be).

Also I know you never asked but you're on the right track for the last challenge, just remember we're comparing to the creation Dates, so youll want to call compare to on the current instances mCreationDate and compare it to bp mCreation date.

Thanks, I hope this explains it, if not feel free to shout out.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

You are accidentally calling the method inside the method. This is called infinite recursion, and I'm guessing it's causing timeouts.

As Craig stated you are calling the method inside the method, so that means you forgot the curly braces for your if statement. Other than that your code looks correct IF you correct add the curly braces for the if statement. Also the question asks you to leave the return 1; in it's place.

@Override
class ... ... {
if (......) {

}
return 1;
}