Hello,

I have written some code that spans 5 different files, which are all in a folder called Employee. The code runs fine without a package, but i have an assignment to package them. When i try to compile the object method which contains all the get and set methods,

private int employeeNumber;
	private Name employeeName = new Name();
	private Date employeeHireDate = new Date();
	private Address employeeAddress = new Address();

The compiler says it cannot find Name, Date, and Address.

All i've done to the previously working code was add: package Employer;
to the start of each file, and an import Employer; to the one which has the main method.


Any help on the issue would be greatly appreciated!

--Spencer

Hi,
With the java import statement you can import only one class file or a list of files in one package .
So if you have a package employer which has a file Name.java, then you have to do
import employer.Name; in the file having the main method
or
import employer.*; which imports all the files in the package. But there is a caveat here. If you have a sub package within employer then the files within that are not imported when you do a import employer.*;

At that time the import statement should be import employer.subpackagename.*;

Note also that if you declare a class as being in package xxx then Java expects to find that class's files in a directory called xxx.
So if you add a package spec to a class, you also need to add the corresponding sub-directory and move your files into it.

Note also that if you declare a class as being in package xxx then Java expects to find that class's files in a directory called xxx.
So if you add a package spec to a class, you also need to add the corresponding sub-directory and move your files into it.

perfect, i realized the item that had the import statement was in the directory too!
Thanks!

This question has already been answered. Start a new discussion instead.