Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Data Structures Getting There Class Review

Amulya Arora
Amulya Arora
6,133 Points

Can someone help? Stuck in Java Data Structures....

These are the errors....I think its a bug.....:- ./com/example/BlogPost.java:2: error: class, interface, or enum expected package com.example; ^ JavaTester.java:62: error: cannot access BlogPost Field[] fields = BlogPost.class.getDeclaredFields(); ^ bad source file: ./com/example/BlogPost.java file does not contain class com.example.BlogPost Please remove or make sure it appears in the correct subdirectory of the sourcepath. 2 errors

com/example/BlogPost.java
import java.util.Date;
package com.example;

public class BlogPost {
  private String mAuthor;
  private String mTitle;
  private String mBody;
  private Date mCreationDate;

}

2 Answers

andren
andren
28,526 Points

The package declaration has to be at the very top of your file, there cannot be anything above it. So you need to swap your import statement and your package statement.

In addition to that you have forgotten to include a private member field for description.

If you fix those two issues like this:

package com.example; // Moved package declaration to top
import java.util.Date;

public class BlogPost {
  private String mAuthor;
  private String mTitle;
  private String mBody;
  private String mDescription; // Added private field member for description
  private Date mCreationDate;

}

Then your code will pass the first task.

Amulya Arora
Amulya Arora
6,133 Points

Thanks a lot andren ... You really helped me a lot...