The solution for the main class not found or cannot be loaded under eclipse

Sometimes Eclipse will get nervous, a good project just can't be compiled, and even Hello World will report the error "cannot find or load the main class", I have encountered it several times, I used to be too lazy to go to the bottom and just rebuild the project directly , but there are too many encounters and must be studied in depth. Now we summarize several solutions. You can try them one by one according to your own situation.
1. It is because the .java file is not in the src path of the project, that is to say, the source code is not compiled by eclipse, and the bytecode does not exist and cannot be run. Right-click on the project name -> Builder Path -> Configure Build Path -> select Source On the panel, click Add Folder, add the upper directory of the package path where the source code is located, and if you write the two classes in one file, when you right-click and select Run As Java Appication, put the cursor to include

2. The quickest solution is to open the class with the main function, ctrl +A (select all) ---> ctrl +X (cut) -----> ctrl+S ( Save)--->Close--->Open again--->ctrl+C (Paste)--->OK; in one sentence, paste it out, close it, and paste it in
. 3. Rebuild the Project.
4. Maybe a jar package is unavailable in Libraries in the Java Build Path of the project, and a red cross is displayed. This means that the system cannot find the jar file, and the jar can be deleted or reloaded.
5. If the above does not work, you can directly run javac under cmd and then try to run java. If it reports an error, then there is a problem with your jdk or os environment.
6. It may be that when you closed eclipse, you did not close the main function first. So when restarting, you need to turn off the java run item in the task manager

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326515126&siteId=291194637