Workaround for the main class cannot be found under Eclipse or cannot be loaded

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.