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 trialEleeza Amin
34,496 PointsJava problems with Packages...I'm convinced I'm right...computer disagrees.
So... I was on the Packages Code Challenge on Java Data Structures and I was on task 4 and this was the question:
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 BlogPost object to replace the string formatter.
I did it, just like in the video and I got some compiler errors:
./Display.java:4: error: illegal start of expression
import com.example.BlogPost;
^
./Display.java:4: error: not a statement
import com.example.BlogPost;
^
./Display.java:5: error: cannot find symbol
BlogPost blog = new BlogPost();
^
symbol: class BlogPost
location: class Display
./Display.java:5: error: cannot find symbol
BlogPost blog = new BlogPost();
^
symbol: class BlogPost
location: class Display
4 errors
I literally copied what the video said, and I got the same thing. I looked it up on the forum but there were no posts on this so...do I have a problem?
Here's my code: Display.java
public class Display {
public static void main(String[] args) {
// Your code here...
import com.example.BlogPost;
BlogPost blog = new BlogPost();
System.out.printf("This is a blog post: %s %n", blog);
}
}
If anyone knows the answer to the problem that would be awesome.
Thanks Treehouse! ~ Eleeza
1 Answer
Kyle Gunby
23,838 PointsYour import statement needs to be at the top of the file, outside of the class.
import com.example.BlogPost;
public class Display {
public static void main(String[] args) {
// Your code here...
BlogPost blog = new BlogPost();
System.out.printf("This is a blog post: %s %n", blog);
}
}
Eleeza Amin
34,496 PointsEleeza Amin
34,496 PointsHi, thanks for the response, but it didn't work for me. I don't know if this is a technical issue with my computer or something...maybe?
I got 3 out of the 4 errors again:
./Display.java:1: error: BlogPost is not public in com.example; cannot be accessed from outside package import com.example.BlogPost; ^ ./Display.java:6: error: cannot find symbol BlogPost blog = new BlogPost(); ^ symbol: class BlogPost location: class Display ./Display.java:6: error: cannot find symbol BlogPost blog = new BlogPost(); ^ symbol: class BlogPost location: class Display 3 errors
But anyway, thanks for responding :)
Kyle Gunby
23,838 PointsKyle Gunby
23,838 PointsLooking at the error, I'd go back to the BlogPost file and make sure that you are declaring the class as public.
Eleeza Amin
34,496 PointsEleeza Amin
34,496 PointsIt works now! Thanks so much :)