Java Package: the main class cannot be found or loaded. javapackage
Chapter 10 of CoreJava
The following error occurs when javac SimpleFrameTest. java and java SimpleFrameTest are used in cmd:
The primary class cannot be found or loaded.
The reason is not the configuration of classpath, but the source code directory is incorrect.
CoreJava:
When running the javac command, the directory requirements are not high. You can compile it elsewhere, paste the generated. class file under BASE/simpleFrame, and run java simple. SimpleFrameTest in the BASE folder.
However, it is best to follow the above instructions to place source files into a subdireory ory that matches the full package name.
Reference: http://blog.csdn.net/changtianshuiyue/article/details/6200791
In Eclipse, the main class with the same name of the project is directly placed in the src directory. For other packages, the main class of each. java file must be consistent with the file name, and the package name must be consistent with the folder.
For example:
SimpleFrameTest. java:
Ex05.java
package simpleFrame;import java.awt.*;import javax.swing.*;/** * @version 1.33 2015-05-12 * @author Cay Horstmann */public class SimpleFrameTest{ public static void main(String[] args) { EventQueue.invokeLater(() -> { SimpleFrame frame = new SimpleFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }); }}class SimpleFrame extends JFrame{ private static final int DEFAULT_WIDTH = 300; private static final int DEFAULT_HEIGHT = 200; public SimpleFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); }}