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 Java Objects (Retired) Delivering the MVP Wrapping up

Corbin Gjerstad
Corbin Gjerstad
1,458 Points

Program won't provide an output

No matter what I try its acting like the code is never entering the main. Even commenting the rest of my code out it won't run a System.out.println, I even tried to divide by 0 to forcibly break it and nothing.

At this point I assume I overlooked something really simple. I just can't figure out what it is.

ForumPost.java
public class ForumPost {
  private User mAuthor;
  private String mTitle;
  private String mDescription;

  public ForumPost(User author, String title, String description) {
    mAuthor = author;
    mTitle = title;
    mDescription = description;
  }

  public User getAuthor() {
    return mAuthor;
  }

  public String getTitle() {
    return mTitle;
  }

  public String getDescription() {
    return  mDescription;
  }

  // TODO: We need to expose the description
}
User.java
public class User {
  private String mFirstName;
  private String mLastName;

  public User(String firstName, String lastName) {
    // TODO:  Set the private fields here
    mFirstName = firstName;
    mLastName = lastName;    
  }

  public String getFirstName() {
    return mFirstName;
  }

   public String getLastName() {
    return mLastName;
  }

}
Forum.java
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());

  }
}
Example.java
public class Example {
    public static void main(String[] args) {

      int one;

      one = 1 / 0;

      System.out.println("testMain");

      /*
      System.out.println("Starting forum example...");
      //if (1 == 1) {
      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("Corbin", "Gjerstad");
      //Add the author, title and description
      ForumPost post = new ForumPost(author, "Java Almost!", "Starting to get java! I may be a programmer yet!");
      //System.out.printf("test1");
      forum.addPost(post);

      */
  }
}
Corbin Gjerstad
Corbin Gjerstad
1,458 Points

I copied my code into a workspace to test it and it works fine. S I think there is a bug with the wrapping up task when I enter the code into the provided editor.

3 Answers

You need catch the exception that divide by zero is launch. Put System.out.println above the division and you see output.

Corbin Gjerstad
Corbin Gjerstad
1,458 Points

Luiz Carlos, I appreciate the help. Unfortunately the issue is it doesn't appear to even enter the main. Even if the only code in the main is a system.out I still get nothing in the output.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hmmm...your exact code helped me generate a bummer message about divide by zero. Want to just re-add all that code and click next 4 times? (If you edit your original post it is in order of the tabs, so just copy and paste)

Unfortunately at the moment there is no way to view your console output. We are working on that right now, but that is not present in any Java code challenge.

There is still an error, but you are super close! Sorry for the frustration, but I can't seem to recreate.

Corbin Gjerstad
Corbin Gjerstad
1,458 Points

Arugh..... I got so caught up in the fact I couldn't see the output... I see what I did wrong now....

Thank you for the help, knowing that I won't see a output during the challenge was just the clue I needed to solve it.