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 Packages

Cannot find symbol error

Any care to tell me why I'm getting cannot find symbols in Workspaces? https://w.trhou.se/m5d4fbrtzi

3 Answers

Nikhil Rai
Nikhil Rai
15,391 Points

Okay. as far as I believe you can simply think of import "com.teamtreehouse.XYZ" is the path of your file in the workspace.

Therefore, according to the tutorial ... if it says.. "import com.teamtreehouse.XYZ" that means in your workspace there is a folder named "com" in which another folder is "teamtreehouse" and then finally you have your java file named XYZ.

Try to think as normal folder system. you are just addressing the path.(Somebody please correct me if I am wrong!!)

So for you the solution would be :

  1. Go to left panel in workspace- right click - create new folder - name it "com"
  2. Right click on "com" - create new folder - name it "teamtreehouse"
  3. Right click on "teamtreehouse" - create new file - name it "Treet.java"

** Also remember to notify your Treet.java that it is a part of the package by putting in the statement : package com.teamtreehouse; (Also displays the address where the class is saved)

By doing this, when ever the package will be accessed, you would be able to access this class, as it will be defined that it is a file saved in a package with the name com having folder named teamtreehouse.

Example.java is the file that should be in the "root" of your workspace. For eg. in my case, I have Example.java(containing the main method) is saved in the directory where "com" is created. To simplify:

my path is :

JAVA_assignments is my workspace - I created the "com" folder following above steps in "JAVA_assignments" - Once I am done creating the package - I came back to "JAVA_assignments" (where I creaed "com" folder) and created a file named Example.java. This will IMPORT the java file "Treet.java" from the package with the command "import com.teamtreehouse.Treet; " , using this command you are telling your program that you want to import the Treet.java file to used in in your "main method" which is located in the folder system com - teamtreehouse - Treet.java.

You only need to run and compile example.java because you have imported it and .. when you will compile the Example.java (containing the main method), it will automatically compile the files you are importing. (Amazing.. Isn't it!! )

Hope this helped... !! cheers.

If you have further question feel free to put it up!!

Seth Kroger
Seth Kroger
56,413 Points

When you use the statement import com.teamtreehouse.Treet; it expects the .java/.class file for Treet to be in a certain folder. Namely inside a folder named treehouse which is inside a folder named com. Instead of folders, your workspace has blank files named treehouse and com. Remove those files and make new folders instead. Alternately you can type the following commands into the console:

mkdir com                                               
mkdir com/treehouse  

Then refresh the left pane. After that you just move the Treet.java file to the treehouse folder.

Donovan Matthysen
Donovan Matthysen
4,370 Points

I had the same issue. Example.java was in the wrong folder.