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 Packages

Can't find error...

I can't see an error, but it says there is (are).

com/example/BlogPost.java
package com.example;
public class BlogPost(){
}
Display.java
public class Display {
  public static void main(String[] args) {
    import com.example.BlogPost;
    BlogPost bp = new BlogPost();
    System.out.printf("This is a blog post: %s", bp);

  }
}

1 Answer

andren
andren
28,558 Points

The code you added for the last task (creating and printing a BlogPost) is fine, but the code you wrote to create the BlogPost class and to import it have faults, your code should not actually have gotten all the way to task 4, but the challenge checker is sometimes a bit faulty in it's error checking.

The problem is that firstly, when creating a class you shouldn't include parentheses after the name, that is only done for methods and the like. Secondly in Java import statements have to be at the top of the file (directly below the package statement if there is one) placing them within a method is not allowed.

So the solution looks like this:

BlogPost.java:

package com.example;
public class BlogPost {
}

Display.java:

import com.example.BlogPost;

public class Display {
  public static void main(String[] args) {
    BlogPost bp = new BlogPost();
    System.out.printf("This is a blog post: %s", bp);

  }
}

Thank you! :)