Java Package: the main class cannot be found or loaded. javapackage

Source: Internet
Author: User

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);   }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.