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
Vasile Rimis
1,672 PointsForum.java NullPointerEcxeption starting on line 10
public class Forum { private String mTopic;
public String getTopic() { return mTopic; }
public void addPost(ForumPost post) { System.out.printf("New post from %s %s about %s %s.\n", post.getAuthor().getFirstName(), post.getAuthor().getLastName(), post.getTitle(),post.getDescription());
} public Forum(String Topic){ mTopic = Topic; } }
1 Answer
Jeremy Hill
29,567 PointsI'm not sure if I fully understand what is going on in your code but if you have created a class called ForumPost then your code should look more like this:
public class Forum{
private String mTopic;
public Forum(String Topic){ // constructor should go here
mTopic = Topic;
}
public String getTopic(){
return mTopic;
}
ForumPost post = new ForumPost(); // instantiate your class here and use its methods below.
public void addPost(){
System.out.printf("New post titled %s from %s and is about %s.", post.getTitle(), post.getAuthor(), post.getDescription());
}
}
All this is assuming that class ForumPost exists along with all of the methods associated with it.
Vasile Rimis
1,672 PointsVasile Rimis
1,672 PointsThank you very much :)