Unable to find a solution to the main class when running Java program under CMD window

Source: Internet
Author: User

I am a beginner of Java, there is always a problem when running a Java program under the CMD window yesterday, can compile but can't execute.

That is javac when the correct, once the Java is wrong, the hint can not find or unable to load the main class, after Baidu Google plus their groping finally solved the problem.

Now summarize the possible solutions to such problems.

1. Check the environment variable path configuration error.

Java_home is the path to the JDK, Classpath is the Lib path (remember to add it before.) These two), path is the route of the bin.

2. Change the path of the classpath.

For example, my original is. C:\Program Files\java\jdk1.8.0_101\lib

instead.; C:\Program Files\java\jdk1.8.0_101\lib\dt.jar; C:\Program Files\java\jdk1.8.0_101\lib\tools.jar

That is, the original based on the refinement of the addition of Dt.jar and Tools.jar. (I tried this at the time, someone said so.) )

3.java and Javac versions are inconsistent.

In the cmd window, enter java-version and javac-version to see if the version is consistent, and if the inconsistency is preceded by the path variable%java-home%\bin

4. Remove the package name.

That is, remove the first line of code from the. java file.

There is a problem with the 5.cmd window Input command.

When Javac is the filename plus. Java,java, nothing is added to the file name. Example: Javac d:helloworld.java java D:helloworld

There is the file in the folder, of course, each folder to write out (I usually put the root directory, convenient).

I was the use of method 4 to solve, as to the other methods do not know whether it can, just the solution to the time encountered to summarize, as to why this, hehe \ Smiley

Unable to find a solution to the main class when running Java program under CMD window

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.