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

Forum Objective Task 4...

I get the following compiler errors to my code but I don't understand what I need to do to fix it:

./Forum.java:7: error: variable topic is already defined in class Forum } Forum topic = new Forum("topic"); ^ ./Main.java:16: error: cannot find symbol forum.addPost(post); ^

Here is my code in the Main and Forum tabs:

public class Main {

public static void main(String[] args) { System.out.println("Beginning forum example"); if (args.length < 2) { System.out.println("Usage: java Main <first name> <last name>"); System.err.println("<first name> and <last name> are required"); System.exit(1); }

Forum forum = new Forum("Java");
// TODO: pass in the first name and last name that are in the args parameter
User author = new User(args[0], args[1]);
// TODO: initialize the forum post with the user created above and a title and description of your choice
ForumPost post = new ForumPost(author, "The title", "The description");
forum.addPost(post);

}

}

public class Forum { private String topic;

// TODO: add a constructor that accepts a topic and sets the private field topic public Forum(String topic) { this.topic = topic; } Forum topic = new Forum("topic");

public String getTopic() { return topic; }

Can someone please help?

1 Answer

Pratham Mishra
Pratham Mishra
14,191 Points

Just delete Forum topic = new Forum("topic"); And you are good to go.