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 trialAbdullah Nazeer
239 PointsWhat's wrong with my code?
What's wrong with my code
package com.example;
public class BlogPost;
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
Joseph Wasden
20,406 PointsThere 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
}
}
mongst
10,841 Pointsmongst
10,841 PointsThank you! This helped me as well. +1