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 trialashmagupta
6,595 PointsHi, I am getting errors while trying to create packages. I tried deleting the files and creating it again.
I am getting errors while trying to create packages. I tried deleting the files and creating it again but it says cannot find symbol Treet.
1 Answer
Tracy Bowers
6,816 PointsThe package declaration belongs at the very top of the file it sets the name space for all that follows.
Note the Example.java file is not in the same folder as the Treet.java file. It is also in the "default package" because no package is defined.
First, your directory structure should match the package declaration.
Example.java | -- com(directory) | -- teamtreehouse(Directory) | Treet.java Treets.java
Next you need to import your classes. The following is your Example.java file. Because Treet.java is not in the same directory you will need to import the class.
--- start of Example.java file ---
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); }
--- end of Example.java file ---
This would be the Treet.java file. Note that the Treet.java class defines its own package. Note the package declaration follows the directory structure: com/teamtreehouse except the use of a period. :-)
--- start of Treet.java file ---
package com.teamtreehouse;
} Treet.java
public class Treet {
}
--- end of Treet.java file ---
Hope this helps.
ashmagupta
6,595 Pointsashmagupta
6,595 PointsThis is the code written but couldn't understand it why it is showing me error of " Example.java:1: error : package com.teamtreehouse doesnnot exist import com.teamtreehouse.Treet" ^ Example.java: 6: error: cannot find symbol symbol: class Treet location: class Example 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 package com.teamtreehouse;
public class Treet {
}