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 Getting There Class Review

Ludwing Najera
Ludwing Najera
4,596 Points

My 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
Ludwing Najera
4,596 Points
package com.teamtreehouse;

import com.teamtreehouse.Treet;

import java.util.Date;


public class Example {

  public static void main(String[] args) {
   Treet treet = new Treet("craigsdennis", "Want to be famous? Simply tweet about " +
   "java and use the hashtag #treet. I’ll use your tweet in a new @treehouse course" +
   " about data structures.",
   new Date(1421849732000L));
   System.out.printf("This is a new Treet:  %s %n", treet);
  }

}
Ludwing Najera
Ludwing Najera
4,596 Points
package 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
Ludwing Najera
4,596 Points

My file directory:

->com

--->teamtreehouse

------>Treet.java/.class

->Example.java/.class

Bob Allan
Bob Allan
10,900 Points

Hi Ludwing,

What exactly are you entering on the command line? That might be the problem (we should at least eliminate the possibility).

Ludwing Najera
Ludwing Najera
4,596 Points

I am typing the command: clear && javac Example.java && java Example

1 Answer

In 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.