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 trialshaji ali
3,302 PointsI expected to see names I passed in through args but I do not.
The task is finished but I still get the error, WHat should I do?
public class ForumPost {
private User mAuthor;
private String mTitle;
private String mDescription;
public ForumPost(User userAuthor, String title, String description){
this.mAuthor=userAuthor;
this.mTitle=title;
this.mDescription=description;
}
public String getDescription(){
return mDescription;
}
public User getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
// TODO: We need to expose the description
}
public class User {
private String mFirstName;
private String mLastName;
public User(String firstName, String lastName) {
this.mFirstName=firstName;
this.mLastName=lastName;
}
public String getFirstName(){
return mFirstName;
}
public String getLastName(){
return mLastName;
}
}
public class Forum {
private String mTopic;
public Forum(String topic){
mTopic=topic;
}
public String getTopic() {
return mTopic;
}
public void addPost(ForumPost post) {
// When all is ready uncomment this...
System.out.printf("New post from %s %s about %s.\n",
post.getAuthor().getFirstName(),
post.getAuthor().getLastName(),
post.getTitle());
}
}
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("Asser", "Moussa");
//Add the author, title and description
ForumPost post = new ForumPost( author ,"Kotla fel Fara3","Book");
forum.addPost(post);
}
}
1 Answer
Ken Alger
Treehouse TeacherShaji;
For this code challenge, in Example.java
we are wanting to be able to pass in names of various authors. You have hard coded the name and therefore when the challenge engine is passing in "William Shakespeare" for the name, it can't do anything with it. That is what the error is saying. Try using args[0]
and args[1]
instead. You might have better luck.
Also, just as a matter of cleaner code, you don't need the this
in front of your member variables in ForumPost.java
or User.java
. If you would like further explanation on that, post another question in the forum and tag me in there and either myself or someone else will provide the explanation.
Happy coding,
Ken