Java Java Objects Delivering the MVP Forum

Rafał Stasiak
Rafał Stasiak
3,762 Points

After uncomment ther is syntax error.

Hello, After rechecking work I get below syntax error. Can someone help with fixing my code?

./Main.java:11: error: constructor Forum in class Forum cannot be applied to given types; Forum forum = new Forum("Java"); ^ required: no arguments found: String reason: actual and formal argument lists differ in length Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

Rafał Stasiak
Rafał Stasiak
3,762 Points

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");
User author = new User("John", "Brown");
ForumPost post = new ForumPost(author,"NewStart","BecomeProgrammer");
forum.addPost(post);

}

}

1 Answer

Daniel Turato
PRO
Daniel Turato
Java Web Development Techdegree Graduate 30,107 Points

A few things, make sure you uncommented the code in Forum. Also, the author object needs to be created by using the values passed in args like so:

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, "test", "test");
    forum.addPost(post);
Rafał Stasiak
Rafał Stasiak
3,762 Points

Hello Daniel,

I created new post with all my code. Please look on this

https://teamtreehouse.com/community/all-time-syntax-error