Sometimes Eclipse will be insane, and project will not compile, and even Hello world will not find or load the main class (Exception in Thread "main" Java.lang.NoClassDefFo UNDERROR:XXX)"error, I have met several times, was not bothered to delve directly into the project, but encountered a number of times must go deep down, and now summarize several solutions, we can try each one according to their own situation.
1, because the. java file is not within the SRC path of the project, that is, the source code is not compiled by Eclipse, the bytecode does not work, the project name is right---Builder path, Configure Build path, Select the source panel, add folder, add the upper directory of the package path where the source code is located, and if you are writing two classes in a file , when you right-click the run as Java appication, To put the cursor on the class that includes the main method (equivalent to specifying the main class entry).
2. In the Java Build path of the project, the libraries may not be available in a jar package, showing a red fork . This indicates that the system cannot find this jar file, remove or reload the jar.
3, in some cases, the quickest solution is to open the class with the main function, CTRL +a (select All)---> Ctrl +x (CUT)-----> Ctrl+s (SAVE)---> Close----> Then open--->ctrl +v (paste)---->OK; A word is cut off and glued in. (equivalent to having eclipse recompile, if you turn on automatic compilation.) )
4, the most common problem should be the following situation: The package is treated as a folder, resulting in all the. java files cannot be recognized by Eclipse, the main function can not be recognized naturally, it will not compile and run, case:
At this time the fastest solution is to right-click the source folder selection:
src > Remove from Build path→src > Build path > Use as Source Folder
Finally, the difference between folder and package: folder by the "/" to carry out the division, the package by "." To divide the hierarchy.
5. In the worst case scenario, you'll have to rebuild Project. (This is the most soil but the most effective solution)
6, if not, we directly under the cmd Javac and then Java run try, if this all error, it is your JDK or OS environment has a problem.
Workaround for the main class cannot be found under Eclipse or cannot be loaded