java HelloWorld times error: "The main class cannot be found or cannot be loaded" solution to the problem

Source: Internet
Author: User

When I was doing a Java primer, the first Java program written in the tutorial was:

public class HelloWorld {/*    first Java program     * It will print a string Hello world     *    /public static void main (string []args) {
    system.out.println ("Hello World"); Print Hello World    }}

The suffix of this file is. java, then use cmd (Command prompt tool) to type in the current directory: Javac Helloworld.java, and then press the ENTER key to generate a class file with the suffix. Class in the current directory. Then when I type in cmd: Java HelloWorld, and press ENTER to run after the result error: "Cannot find or Load main class".

This problem occurs because the configuration of the environment variable classpath was not configured at the time of the problem, my previous classpath configuration is the JDK installation directory of the Lib folder, namely: "D:\working\Java\jdk-9.0.4\lib". But this is not enough, but also need to precede a period and a semicolon, that is: ".;D: \ Working\java\jdk-9.0.4\lib ". Then close the previous cmd, reopen it into the current directory, then type: Java HelloWorld, press ENTER to run the program, everything is OK.

Good luck!

java HelloWorld times error: "The main class cannot be found or cannot be loaded" solution to the problem

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.