When executing the java file in the Command window, the system prompts that the main class cannot be found or loaded.
When executing the java file in the Command window, the system prompts that the main class cannot be found or loaded.
In the past, java code was written on integrated development tools such as Eclipse or IDEA. Therefore, code compilation and testing were performed with one click. The principle is simply as follows, that is, run the javac command. compile java files. class file, and then run the java command. class file, and finally get the results of the program. As for the underlying things, we will not go into it for the time being. If you are interested, you can take a look at the relevant information such as Java virtual machine. All the work done by running the program was handed over to the compiler. Later, I tried to do this manually.The following error is prompted:
Then I went to the Internet to check it and found that many of my colleagues have encountered this problem.
Let's take a look at my test project directory. This makes it clearer.
I directly created two. java files under the folder, A. java and B. java. The javatest function is similar to the package in java. The code of the two files is as follows:
A. java
B. java
Next, compile the java file.
In this way, two. class files are obtained: A. class and B. class.
Finally, execute the B. class file.
As you can see, the error message is: the primary class B cannot be found or loaded.
Then I went to the Internet to check the reason why some colleagues said it should be package. Then I tried it:
The results show the program call results.
Another method is as follows:
All in allExecute the. class file containing the main function in the upper-level directory of the package.
This article is just like this. I hope to help students who encounter such problems a little bit. Thank you!