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