Eclipse Run Exception: Could not find the main class.

Source: Internet
Author: User

Eclipse appears could not find the main class, mostly due to improper JDK versions used.


Exception reason: When you use the Eclipse tool to create a new Java project named MyProj, and in which a simple Java class is created to run the test, Eclipse throws the name "could not find" main class. Program'll exit. " The exception.

Verification reason: There are multiple JDK versions on this machine (that is, 1.4 and 1.5 two versions), resulting in an exception because the default JDK version of MyProj is inconsistent with the JDK version used by the Eclipse tool.

Workaround: Make the MyProj default JDK version consistent with the JDK version used by the Eclipse tool. The specific treatment method is as follows.

1, first check the JDK version used by Eclipse. Window--> Preferences--> Java--> installed JREs. View the currently used JDK version in the installed JREs window on the right (JDK1.4 is set up on this machine).

2, mouse click MyProj Project, so that the mouse focus on the project, and then click the menu bar Project--> Properties--> Java Compiler. In the JDK compliance on its right, see if the JDK version in the compiler compliance level is consistent with the JDK version viewed above, and if it is inconsistent, keep it consistent ( The default version of the project in this machine is 5.0, and its version number is modified to 1.4.

Note: If the column is dead Gray and cannot be edited, click on the above name to enable project specific settings checkbox to modify the JDK version



There are several places under eclipse that need to use JRE. The first is compiler use, the second is development use, and the third is run-time use.
Unfortunately, these three are configured separately, and your problem is that there is a version conflict between the three packages in eclipse.
You can check the eclipse's JRE configuration process online. Try to replace the eclipse's own JRE with the official version, preferably in the same edition.

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.