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
David B Dinkins
71,472 PointsStage 4, Wrapping Up, Challenge Task 4 of 4
I think I've done everything correctly in this final challenge. I don't have any bugs appearing in my Preview, but I'm getting an error that says "Bummer! Try again!". I've already uncommented addPost in Forum.java and worked through the commented out code in Example.java. Anyone else stuck?
Forum.java:
public void addPost(ForumPost post) {
System.out.printf("New post from %s %s about %s.\n",
post.getAuthor().getFirstName(),
post.getAuthor().getLastName(),
post.getTitle());
}
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");
// 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, "Doctor", "Likes to Save Lives");
forum.addPost(post);
}
}
2 Answers
Craig Dennis
Treehouse TeacherAha! Try fixing the constructor in ForumPost to initialize the member fields. I'll track down why that isn't giving you a compiler error....it should!
Let me know if that works! Sorry for the stump :(
Craig Dennis
Treehouse TeacherYikes! So close, it's looking great, in fact so great I don't see any errors.
Can you show me ForumPost.java please?
David B Dinkins
71,472 PointsYup, here's what I've got:
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) {
}
}
Actually, I just figured it out as I was putting together this comment. I had not added the private fields to store the Constructor's parameters. Thanks for pointing me in the right direction, Craig!
Edane Barton
11,457 PointsEdane Barton
11,457 PointsI see and resolved my issue, but I am still confused on why we needed to pass in arrays such as 'new User(args[0], args[1]) and not our name '
And not enter a string: new User("FirstName", "LastName")