The problem of "cannot be found or the main class cannot be loaded" occurs with the java command in CMD.

Source: Internet
Author: User

Problem description:

Compile a simple Hello. java program and use the javac Hello. java command in the cmd command line to compile the program. The Hello. class file can be generated. However, after you enter the java Hello command (the file directory is the same as the command directory), the error message "cannot be found or the main class cannot be loaded" is displayed ". Solution: Find the cause and solution from the Internet, and refer to the Environment Variable classpath setting problem, but the problem still persists after multiple attempts. Run java-cp % classpath; Hello. The result is correct. Use echo % classpath % or set classpath to view the classpath environment variable value. It is found that only the classpath value in the current user variable is displayed, rather than the classpath value in the system variable. Solution 1: add the classpath value in the system variable to the user variable and execute java Hello! Use java-cp % classpath; Hello to execute, still correct! Solution 2: add the classpath value in the system variable to display the current path strength, for example, the difference between searching for user variables and system variables online. The user variables are used by the current user, if you log on with another user, this environment variable does not work (private ). System variables are available to all users (public ). But I still don't know why?

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.