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

Ben Jeffers
Ben Jeffers
1,066 Points

Why am I getting syntax errors on the imports?

For this challenge I just had to implement Comparable and write a compareTo method which I think I did but when I check my work it keeps giving me these error messages about the import and the package which I didn't even write in this challenge and I have no idea why.

JavaTester.java:67: error: illegal start of expression package com.example; ^ JavaTester.java:67: error: not a statement package com.example; ^ JavaTester.java:69: error: illegal start of expression import java.util.Date; ^ JavaTester.java:69: error: not a statement import java.util.Date; ^ JavaTester.java:71: error: illegal start of expression public class BlogPost implements Comparable{ ^

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){
    return 1; 
  }
}

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Ben Jeffers

On a quick glance, your code does seem correct! :thumbsup:

From the posts I've seen recently in the Community (and with some self checks), there seems to be some technical issues with the Java challenges. I'm sure the Support Team is on top of this. For now, You can always continue with the course and come back to the Challenges later on, once the problem has been correct with the Code Checkers. This can be done by manually navigating your progress using the nav links above the video window.

Hope this gets fixed up soon. :) :dizzy: