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 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,558 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...