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 trialMohammed Saif
13,358 Pointswhats wrong in this code ? I cant understand !
Finally, please add a getter method for the body. You didn't think I was going to make you type them all out, did you?!!
package com.example;
import java.util.Date;
public class BlogPost {
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;
}
private class getBody() {
return mBody;
}
3 Answers
Dennis Mårtensson
7,400 PointsFirst of all, it's a getter, as in other classes and files need to be able to utilize the method, so the method has to be 'public' and not 'private'. Second, you have typed in 'class' as the return type. Since the 'mBody' member variable is a String, the method should return a 'String'. So it should look something like this;
public String getBody()
{
return mBody;
}
Hope that helped you! And it if did, please vote this to be the best answer! (:
David Reich
5,518 PointsI'm having the same problem micheala. My code is the same as the above, but I'm getting the same error you are. Did you figure it out?
Sanora Griffin
2,972 Pointsdid anyone ever find the answer to this?
N Elliott
2,628 Pointsput this code inside the class then it works.
Mohammed Saif
13,358 PointsMohammed Saif
13,358 PointsHey thank you so much for explaining, i have understood it now :)
micheala leaver
1,313 Pointsmicheala leaver
1,313 PointsHey when I use that it still says it doesnt work: ./com/example/BlogPost.java:22: error: class, interface, or enum expected public String getBody() ^ ./com/example/BlogPost.java:25: error: class, interface, or enum expected } ^ 2 errors