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

Finally, uncomment the addPost method in Forum.java. Then for the last task, uncomment the main method in Example.java f

Hello everyone,

Im having some hard time trying to solve the last step from exercise posted bellow. I have tried almoust all options available (known by me) and none of them working.

<i>Finally, uncomment the addPost method in Forum.java. Then for the last task, uncomment the main method in Example.java fixing the bugs as you go to use the new working code. For the forum post title and description, use that to shout out about how it feels to complete this challenge. </i>

And this is my trouble code from Example.java

Example.java
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(firstName, lastName);
    ForumPost post = new ForumPost(Author , Title , Description);
    forum.addPost(post);
  }

}
}
ForumPost.java
public class ForumPost {
  private User mAuthor;
  private String mTitle;
  private String mDescription;

  public User getAuthor() {
    return mAuthor;
  }

  public String getTitle() {
    return mTitle;
  }

  public String getDescription() {
   return mDescription; 
  }

  public ForumPost(User Author, String Title , String Description) {
   mAuthor = Author;
   mTitle = Title; 
   mDescription = Description;
  }
  // TODO: We need to expose the description
}
User.java
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.java
public class Forum {
  private String mTopic;

  public String getTopic() {
      return mTopic;
  }

public Forum(String topic) {
   mTopic = topic;

}

  public void addPost(ForumPost post) {

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

  }
}

And those are the errors, they were more different errors but i solved them one by one lurking on google and now im stuck with these:

`` ./Example.java:16: error: class, interface, or enum expected } ^ ./Example.java:10: error: cannot find symbol User author = new User(firstName, lastName); ^ symbol: variable firstName location: class Example ./Example.java:10: error: cannot find symbol User author = new User(firstName, lastName); ^ symbol: variable lastName location: class Example ./Example.java:11: error: cannot find symbol ForumPost post = new ForumPost(Author , Title , Description); ^ symbol: variable Author location: class Example ./Example.java:11: error: cannot find symbol ForumPost post = new ForumPost(Author , Title , Description); ^ symbol: variable Title location: class Example ./Example.java:11: error: cannot find symbol ForumPost post = new ForumPost(Author , Title , Description); ^ symbol: variable Description location: class Example 6 errors

I appreciate any help.

2 Answers

Hi there,

Your issues lie in these two lines, that I can see. There may be other issues once we've got through these.

    User author = new User(firstName, lastName);
    ForumPost post = new ForumPost(Author , Title , Description);

For the User instance, you need to pass it a first & last name as Strings, as you wrote in the constructor. From memory (if you could post a link to the challenge, that would help!) I think the first and last name are passed in as args[0] and args[1] in main, so your instantiation of User could look like:

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

Next, your ForumPost creation uses the author instance you just created above. Then, you need to pass in two strings again, one for the title and one for the description. Try:

ForumPost post = new ForumPost(author, "A Title", "A description");

Have a look at this post that goes through the challenge in detail. Bear in mind that the order of the answers is skewed due to one being marked "Best" - that moves it up to the top.

I hope that helps.

Steve.

Hi Steve And thank you very much for your answer. I managed now to solve the exercise and fixing the last compiler error by adding a comma between args[0] and args[1]

Oops! sorry! Bad place for a typo.

Glad you got it fixed.

Steve.