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

Is there a bug issue on task 4?

I keep getting an error message saying the arguments passed to User author = new User("John", "Smith") is not right. However, the preview output clearly shows it went through. Is anyone encountering the same problem and if so, is there a solution?

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("John", "Smith");
    // TODO: initialize the forum post with the user created above and a title and description of your choice
    ForumPost post = new ForumPost(author, "Ceo", "Working in a workplace");
    forum.addPost(post);


  }

} 

1 Answer

Hi there,

No, there's not a bug. If you read through the comments within the code, you'll see mention of the args array. That is the parameter that the main method receives when the code is first started. So, the name you are looking for is passed in by the user of the code at the outset of the program.

The args is an array of string objects. Your firstName is the first element of the array (args[0]) and the second element is lastName, (args[1]). So, pass those two elements into the User object. Rather than "John", "Smith", send in this:

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

I hope that makes sense!

Steve.

Thanks. This helps a lot.

No problem! :+1: :smile: