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

Java Data Structures: Understanding the file structure

I put my Example.java file into the com folder instead of the Java Data Structures folder and got an error. I know how to fix it, but I don't understand why the error happens. I was hoping someone could explain the file/folder structure to me so I can understand what things should be in a package and what to leave out of a package.

2 Answers

In Example.java, the first line is

import com.treehouse.Treet;

When this runs, the compiler looks for the 'Treet' class. In order to find it, it uses you instructions in the import statement. It goes into the 'com' directory, then to the 'treehouse' directory, and from there it finds the 'Treet' class which you created. Your error occurred because the 'Treet' class is in a package file:

package com.treehouse;

'com' represents a directory while 'treehouse' does, too.

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"