When running the java file in cmd, the solution of the main class cannot be found or loaded.
Recently I looked at java again, but it had been a headache for more than a decade by a seemingly basic hellorworld. Baidu once, if you edit and run the. java file in cmd and report an error, the solution is as follows ,:
The. java file in the root directory of drive D.
Open cmd and enter the root directory of drive d For javac demo. java ,:
In this step, no error is reported, because as long as your classpath is set successfully, no error is reported,
Now we can see that the compiled demo. class has already appeared in the root directory.
When we proceed to the next step, we will find the cmd error ,:
I believe that many new students have encountered this problem, which is time-consuming and laborious for Baidu to query. Sometimes some people write a solution that won't solve the problem at all.
Then we can directly handle the problem. This kind of problem is often caused by incomplete classpath configuration.
:
In the classpath of the environment variable, add "." at the beginning of the variable value, and then run cmd again to solve the problem ,:
For how to configure environment variables, see the previous java Configuration Guide.