When running a Java program in the cmd window, the solution of the main class cannot be found.

Source: Internet
Author: User

When running a Java program in the cmd window, the solution of the main class cannot be found.

I am a beginner in Java. I encountered a problem when running a Java program in the cmd window yesterday. It can be compiled but cannot be executed.

That is, the javac is correct. Once java is incorrect, the system prompts that the main class cannot be found or loaded. Baidu Google and its own exploration finally solved the problem.

Summarize the possible solutions to these problems.

1. Check the environment variable path configuration error.

JAVA_HOME is the jdk Path, CLASSPATH is the lib Path (remember to add ..;), and Path is the bin Path.

2. Change the CLASSPATH path.

For example, my original file is.; C: \ Program Files \ Java \ jdk1.8.0 _ 101 \ lib

To.; C: \ Program Files \ Java \ jdk1.8.0 _ 101 \ lib \ dt. jar; C: \ Program Files \ Java \ jdk1.8.0 _ 101 \ lib \ tools. jar

That is, add dt. jar and tools. jar to the original details. (I tried this at the time, but someone said yes .)

3. the java and javac versions are inconsistent.

Enter java-version and javac-version in the cmd window to check whether the version is consistent. if the version is inconsistent, add % JAVA-HOME % \ bin in front of the Path variable.

4. Remove the package name.

That is to say, remove the first line of code package in the. java file.

5. The command entered in the cmd window is incorrect.

In javac, the file name is added to. java. in java, nothing is added to the file name. Example: javac d: HelloWorld. java d: HelloWorld

In addition, files are stored in folders. Of course, each folder should be written (I usually put it in the root directory for convenience ).

I used method 4 to solve the problem. As for other methods, I don't know if it is possible. I just summarized the solutions I encountered at the time. 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.