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 Data Structures - Retired Getting There Packages

Abdullah Nazeer
Abdullah Nazeer
239 Points

What's wrong with my code?

What's wrong with my code

com/example/BlogPost.java
package com.example;

public class BlogPost;
Display.java
import com.example.BlogPost;

public class Display {
  public static void main(String[] args) {
  BlogPost blogPost= new BlogPost();
  System.out.printf("This is a new blogpost:",blogPost);

  }
}

1 Answer

There are two errors that we need to address:

(1) the class declaration in BlogPost.Java (2) The missing placeholder in the printf String

(1) When declaring a class, you need to include the code block for that class, a code block is defined by a pair of curly braces. See below.

//BLogPost.Java

package com.example;

public class BlogPost {
//this is the code inside the declared code block
}

(2) You are missing the %s placeholder in your printf string. Without this, the variable declaration after the string has no defined location to appear in the string. See below.

import com.example.BlogPost;

public class Display {
  public static void main(String[] args) {
  BlogPost blogPost= new BlogPost();
  System.out.printf("This is a new blogpost: %s", blogPost); // <-- notice the %s inside the string

  }
}

Thank you! This helped me as well. +1