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 trialLudwing Najera
4,596 PointsMy Treet code will not run!
Whenever I attempt to run my java program via the command line, it gives me an error saying that my main class Example cannot be found or loaded.
I have checked a few other questions, and they seem to be linked with the organization of the packages and files, but they seem like they are fine. I will have my code in the comments.
Ludwing Najera
4,596 Pointspackage com.teamtreehouse;
import java.util.Date;
public class Treet {
private String mAuthor;
private String mDesc;
private Date mCreationDate;
public Treet(String author, String desc, Date date) {
mAuthor = author;
mDesc = desc;
mCreationDate = date;
}
public String toString() {
return "Treet: \"" + mDesc + "\" - @" + mAuthor ;
}
public String getAuthor() {
return mAuthor;
}
public String getDesc() {
return mDesc;
}
public Date getDate() {
return mCreationDate;
}
}
Ludwing Najera
4,596 PointsMy file directory:
->com
--->teamtreehouse
------>Treet.java/.class
->Example.java/.class
Bob Allan
10,900 PointsHi Ludwing,
What exactly are you entering on the command line? That might be the problem (we should at least eliminate the possibility).
Ludwing Najera
4,596 PointsI am typing the command: clear && javac Example.java && java Example
1 Answer
Tracy Chacon
7,372 PointsIn Example.java remove the the following statement:
package com.teamtreehouse;
Save and re-run your commands at the command line because these are correct.
In the Packages video Craig explains that this line in the file '...declares that it is part of the package'.
Take a look at the 'file explorer' in the left pane and you can see that Example.java is outside of the com/teamtreehouse directory.
That statement makes the Java complier look for Example.java in the /com/treehouse folder and that is why you get the message that Example.java cannot be found.
Ludwing Najera
4,596 PointsLudwing Najera
4,596 Points