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

Mohammed Saif
Mohammed Saif
13,358 Points

whats 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?!!

com/example/BlogPost.java
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
Dennis Mårtensson
7,400 Points

First 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! (:

Mohammed Saif
Mohammed Saif
13,358 Points

Hey thank you so much for explaining, i have understood it now :)

Hey 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

David Reich
David Reich
5,518 Points

I'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?

did anyone ever find the answer to this?

N Elliott
N Elliott
2,628 Points

put this code inside the class then it works.