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

Mohammed Saif
Mohammed Saif
13,358 Points

can someone tell me whats wrong in this code ?

Now in the main method of Display.java, instantiate a new BlogPost. Use System.out.printf to print out "This is a blog post: %s" and pass in the newly created BlogsPot object to replace the string formatter.

com/example/BlogPost.java
package com.example;
public 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 blog post: %s %n", blogPost);
  }
}

2 Answers

Dennis Mårtensson
Dennis Mårtensson
7,400 Points

Hey again! I noticed now that, in you 'BlogPost.java' file you forgot to write the keyword 'class' after 'public'. My finished code for this challenge looks like this, and it compiled;

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 blog post: %s %n", blogPost);

  }
}

Hope that helped!

Mohammed Saif
Mohammed Saif
13,358 Points

oops that was my mistake thank you for helping me.

Dennis Mårtensson
Dennis Mårtensson
7,400 Points

When you create an object of the class 'BlogPost', you name it 'blogpost';

BlogPost blogpost = new BlogPost();

And then when you try to pass it into the 'printf' method, you try to pass in an object called 'blogPost' (with a capital 'P');

System.out.printf("This is a blog post: %s %n", blogPost);

Either change the name of the object to have a capital 'P', or simply pass in 'blogpost' in the 'printf' method. Hope that helped you, and if it did please vote this to be the best answer!

Mohammed Saif
Mohammed Saif
13,358 Points

hey i am still getting an error after trying that-

./com/example/BlogPost.java:1: error: expected package com.example.; ^ ./com/example/BlogPost.java:2: error: class, interface, or enum expected public BlogPost{ ^ ./Display.java:1: error: cannot access BlogPost import com.example.BlogPost; ^ bad source file: ./com/example/BlogPost.java file does not contain class com.example.BlogPost Please remove or make sure it appears in the correct subdirectory of the sourcepath. 3 errors