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 - Retired Getting There Packages

Jeff Wereb
Jeff Wereb
2,883 Points

Java Data Structures javac Example.java Can not get this to compile.

when running the compile command is get the following over and over: javac: file not found: Example.java
Usage: javac <options> <source files>
use -help for a list of possible options

I have done everything I can think of, delete the files, delete the directories and rebuild them.

Here is my code.

Example.java:

import com.teamtreehouse.Treet;

public class Example{ public static void main(String[] args){ Treet treet = new Treet(); System.out.printf("This is a new Treet: %s %n", Treet); } }

Treet.java:

public class Treet{ }

Check your file structure...i was having the same issue!

Are you doing this in workspace or an IDE?

Sameer Rao
Sameer Rao
490 Points

Issue was with Example.java which was placed within com directory however com directory and example.java should have shared under same parent.

Its working now.

5 Answers

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

Solution: the Example.java file is to be created at the first level. Just inside Java Data Struct.... as if it was a sibling with the folder "com"

Simon Coates
Simon Coates
28,694 Points

Unless you're in the right directory, you can't use a simple path. The simplest approach is to use cd directoryName and cd .. to go back a directory. I copied your code and made a couple modifications. Treet.java became:

package com.teamtreehouse;

public class Treet{ }

Example.java became:

import com.teamtreehouse.Treet;

public class Example{
  public static void main(String[] args){ 
    Treet treet = new Treet();
    System.out.printf("This is a new Treet: %s %n", treet);      //* lower case t on variable
  } 
}

As long as I was in the right directory, javac Example.java ran fine. (where you are in the directory structure should be visible in the prompt)

Simon Coates
Simon Coates
28,694 Points

some of the necessary directory navigation (assuming your files are in the right locations):

treehouse:~/workspace/com$ cd teamtreehouse                                                                                                         
treehouse:~/workspace/com/teamtreehouse$ javac Treet.java                                                                                           
treehouse:~/workspace/com/teamtreehouse$ cd..                                                                                                       
bash: cd..: command not found                                                                                                                       
treehouse:~/workspace/com/teamtreehouse$ cd ..                                                                                                      
treehouse:~/workspace/com$ cd ..                                                                                                                    
treehouse:~/workspace$ javac Example.java                                                                                                           
Example.java:6: error: cannot find symbol                                                                                                           
    System.out.printf("This is a new Treet: %s %n", Treet);                                                                                         
                                                    ^                                                                                               
  symbol:   variable Treet                                                                                                                          
  location: class Example                                                                                                                           
1 error                                                                                                                                             
treehouse:~/workspace$ javac Example.java                                                                                                           
treehouse:~/workspace$ java Example.java                                                                                                            
Error: Could not find or load main class Example.java                                                                                               
treehouse:~/workspace$ java Example                                                                                                                 
This is a new Treet: com.teamtreehouse.Treet@6d06d69c                                                                                               
treehouse:~/workspace$  
Jeff Wereb
Jeff Wereb
2,883 Points

Thank you for the help. I created a new workspace from the template and copied your code in the files. I then ran the javac Example.java command from the com, teamtreehouse and the treehouse directories. I still get the same error.

I've tried this on two different browsers and still get the error.

Simon Coates
Simon Coates
28,694 Points

I included the copy of the console, so you could see where my files were and where I navigated to use the javac without needing to include a more complex file path. This error is usually because the file isn't where it's meant to be, or people are in the wrong directory for the filepath they're feeding into javac. (copying my code would fix one or two errors, but the error you're getting is unrelated to a syntax problem.). If you post a url to a snapshot of your workspace, I can confirm that it should work.

Jeff Wereb
Jeff Wereb
2,883 Points

Here is the path and I can see my error now. You're absolutely right. I put the Example.java file in the treehouse directory not the com directory. Thank you for the help. I'm going to give it a whirl.

https://teamtreehouse.com/workspaces/18464752

Jeff Wereb
Jeff Wereb
2,883 Points

Simon, thank you. That worked. Best answer ever!

Simon Coates
Simon Coates
28,694 Points

cool. That task seem to trip up a lot of people.