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 Objects (Retired) Delivering the MVP Wrapping Up

Michael Kidder
PLUS
Michael Kidder
Courses Plus Student 938 Points

I'm at the end of the wrap up exercise, and I can't get the author names to pass thru. Any direction would be helpful.

This is what I have, but I think I'm not sure how to use the User class correctly.

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");
    // Take the first two elements passed args
    User author = new User(args[0], args[1]);
    // Add the author, title and description
    ForumPost post = new ForumPost(author, "Title", "Desc");
    forum.addPost(post);
  }
}

5 Answers

Michael Kidder
PLUS
Michael Kidder
Courses Plus Student 938 Points

I had to start back from the beginning, and it worked this time, so we can leave that one in the xFiles.

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

I'm not sure if were referring to the same challenge. But if I remember right in the final java objects course challenge you pass in the arguments passed in through the args array in the main method.

User author = new User(args[0], args[1]);

Hopefully were talking about the same challenge.

If not let me know.

Craig Dennis
Craig Dennis
Treehouse Teacher

Bizarre, this looks right, what error are you getting?

Michael Kidder
PLUS
Michael Kidder
Courses Plus Student 938 Points

Bummer! I expected to see the names I passed in through the args, but I do not. Hmm.

I'm thinking I may have forgotten something in 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());
  }
}
Craig Dennis
Craig Dennis
Treehouse Teacher

That looks good. What does User.java look like?

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

i don´t understand this part at all ;( Can somone explain it to me please????

User author = new User(args[0], args[1]);
Benny Ng
Benny Ng
6,462 Points

It is calling the User constructor, which takes two String arguments: the first name and last name. Here, args[0], args[1] refers to first two Strings passed in to the commandline (ie., java Example <myFirstArg> <mySecondArg>).

The User constructor then uses those arguments to set the private member variables mFirstName and mLastName.

Kyle Salisbury
seal-mask
.a{fill-rule:evenodd;}techdegree
Kyle Salisbury
Full Stack JavaScript Techdegree Student 16,363 Points

I had the same problem and the solution I came up was this: In the User.java page, my getter methods would have a string stating firstName = " "; because that was how the hangman game had them. However once I deleted that line of code and just had the getter method to have return mFirstName; Also the same in the getLastName method, (return mLastName;) I was able to pass the challenge.