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

Stuck on Wrapping Up Challenge Task 4 of 4

I'm really stuck on the last part of the challenge and cant see where the code is wrong. The error I get is just Bummer! Try Again! these are my codes:

ForumPost:

public class ForumPost {
  private User mAuthor;
  private String mTitle;
  private String mDescription;

  public User getAuthor() {
    return mAuthor;
  }

  public String getTitle() {
    return mTitle;
  }


  public ForumPost(User author, String title, String description){

     mAuthor = author;
     mTitle = title;
     mDescription =  description;
  }

  public String getDescription(){
    return mDescription;
  }

}

User:

public class User {

  private String mFirstName;
  private String mLastName;

  public User(String firstName, String lastName) {
    mFirstName = firstName;
    mLastName = lastName;
  }

  public String getFirstName(){
    return mFirstName;
  }  

  public String getLastName(){
    return mLastName;
  }  

}

Forum:

public class Forum {

  private String mTopic;

  public Forum(String topic) {
    mTopic = topic;
  }

  public String getTopic() {
      return mTopic;
  }

  public void addPost(ForumPost post) {

      System.out.printf("New post from %s %s about %s.\n",
                         post.getAuthor().getFirstName(),
                         post.getAuthor().getLastName(),
                         post.getTitle());

  }
}

Example:

public class Example {

  public static void main(String[] args) {
    System.out.println("Starting forum example...");

    if (args.length < 2) {
       System.out.println("first and last name are required. eg:  java Example Craig Dennis");
    }
    Forum forum = new Forum("Java");
    User author = new User(args[0], args[1]);
    ForumPost post = new ForumPost(author, "Javas Cool", "Whoop!");
    forum.addPost(post);
  }


}

Been at it for over an hour and can't figure it out

Cheers

4 Answers

Thanks for the reply! It worked for me to when I tried it again just now. Must of had a bad connection or something

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

I just tried it with your code.. and it worked. Try again and let me know if its not working.

Sorry for the frustration, but great job!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Sorry 'bout that Tom, congrats on completing the course!

Hello Craig, i know im 2 months late on this discussion, but my code is very similar to this, the only difference being in the text behind ForumPost post = new ForumPost. However, when i submit mine, i keep getting the error code "Bummer! java.lang.NullPointerException (Look around Forum.java line 13)"

Craig Dennis
Craig Dennis
Treehouse Teacher

Aaron Sikorski I am assuming you are missing the initialization in one of the constructors. Can you share your code?

After messing around with my code some, i got it to work. Thank you though, and the Hangman game came out great! Can't wait to work on future projects!