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
Ileana Bunea
1,117 Pointspackage and import error when compiling Example.java - I keep getting this error
I keep getting this error: ./com/teamtreehouse/Treet.java:3: error: class, interface, or enum expected
package com.teamtreehouse;
^
Example.java:3: error: cannot access Treet
import com.teamtreehouse.Treet;
^
bad source file: ./com/teamtreehouse/Treet.java
file does not contain class com.teamtreehouse.Treet
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
I made sure that I created the folders so that teamtreehouse is a subdirectory to com and Treet.java is in teamtreehouse. What am I doing wrong?
Here's the Treet.java code: import java.util.Date; package com.teamtreehouse;
public class Treet { private String mAuthor; private String mDescription; private Date mCreationDate;
public Treet(String author, String description, Date creationDate) { mAuthor = author; mDescription = description; mCreationDate = creationDate; } public String getAuthor() { return mAuthor; } public String getDescription() { return mDescription; } public Date getCreationDate() { return mCreationDate; } }
and here is the Example.java code: import java.util.Date; import com.teamtreehouse.Treet;
public class Example {
public static void main(String[] args) {
Treet treet = new Treet("infogeek87", "a tweet from me, I never tweet", new Date(1423907008000L));
System.out.printf("This is a new treet: %s %n", treet);
} }
I am really sorry for the looong question.
1 Answer
Ileana Bunea
1,117 PointsGot it, I will answer to myself: I had to switch these 2 lines in Treet,java: first should be package com.teamtreehouse;
and then the import line import java.util.Date;
That's it and everything works just fine.