Here is my problem:-

On my desktop, there is a folder called "Test."
In Test, there is a folder called "toUse."
In "toUse," there is a java source file called "Test" and three folders, namely "Print," "SwingFrame" and "TextFileWriter."
The source file for "Test.":-

package Test.toUse;
import Test.toUse.Print.Printer;
public class Test {
	public static void main(String[] args) {
		Printer p = new Printer();
		p.printMe("It worked!");
	}
}

In the folder "Print", there is a source file called "Printer" and it's class file:-

package everydayUse.Print;
public class Printer {
	public void printMe(String toSay) {
		System.out.println(toSay);
	}
}

In the folder "SwingFrame", there is a source file called "FrameMaker" and it's class file:-

package everydayUse.SwingFrame;
import javax.swing.*;
public class FrameMaker {
	public JFrame createFrame(String title, int width, int height) {
		JFrame frame = new JFrame(title);
		frame.setSize(width, height);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		return frame;
	}
}

In the folder "TextFileWriter", there is a source file called "TextFileWriter" and it's class file:-

package everydayUse.TextFileWriter;
import java.io.*;
public class TextFileWriter {
	public void write(String fileName, String toWrite) {
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
			writer.write(toWrite);
			writer.close();
		}
		catch (Exception ex) { ex.printStackTrace(); }
	}

}

When I try to compile Test.java, this is the error I get:-

Test.java:2: package Test.toUse.Print does not exist
import Test.toUse.Print.Printer;
                       ^
Test.java:5: cannot find symbol
symbol  : class Printer
location: class Test.toUse.Test
                Printer p = new Printer();
                ^
Test.java:5: cannot find symbol
symbol  : class Printer
location: class Test.toUse.Test
                Printer p = new Printer();
                                ^
3 errors

package everydayUse.Print;
here you are saying that your Print class is inside the package everydayUse.Print;
but you are not importing a package named everydayUse anywhere.

What is the value of the classpath when you try to compile the program?
The classpath should contain the folder that contains the start of the package path.
The classpath plus the package path should point to the class file. There should not be any overlap between the two paths.

Now this error:-

Test.java:2: package Test.toUse.Print does not exist
import Test.toUse.Print.Printer;
                       ^
Test.java:5: cannot find symbol
symbol  : class Printer
location: class Test.toUse.Test
                Printer p = new Printer();
                ^
Test.java:5: cannot find symbol
symbol  : class Printer
location: class Test.toUse.Test
                Printer p = new Printer();
                                ^
3 errors

import Test.toUse.Print.Printer

as you said:
package Test.<folder>
but toUse.Print. => implies two folders where you have <one folder>

I have deleted the second copy(i.e.:everydayUse).
Now the only one copy is Test.<folder>

This article has been dead for over six months. Start a new discussion instead.