Eclipse 出现could not find the main class, 多半是由于使用的JDK版本不当引起的。
异常原因:使用Eclipse工具新建一个名为MyProj的java工程,并在其中创建一个简单的java类进行运行测试时,Eclipse抛出名为“Could not find the main class.Program will
exit.”的异常。
核查原因:本机上存在多个JDK版本(即:1.4和1.5两个版本),由于MyProj的默认JDK版本与Eclipse工具使用的JDK版本不一致,所以产生如上异常。
解决办法:使MyProj默认的JDK版本与Eclipse工具使用的JDK版本保持一致即可。具体处理方式如下。
1、首先核查Eclipse使用的JDK版本。Window --> Preferences --> Java --> Installed JREs。在右侧的Installed JREs窗口中查看当前使用的JDK版本(本机设置的是JDK1.4)。
2、鼠标点击MyProj工程,使鼠标聚焦在该工程上,然后点击菜单栏Project --> Properties --> Java Compiler。在其右侧的JDK Compliance中,查看Compiler compliance level中的JDK版本是否与上面查看的JDK版本一致,若不一致,使其保持一致即可(本机中该工程默认的版本为5.0,将其版本号修改为1.4即可)。
注:若该栏为死灰色无法编辑,请点击上面的名为Enable project specific settings复选框即可进行JDK版本的修改
eclipse下有几个需要使用jre的地方。第一个是编译器使用,第二个是开发使用,第三个是运行时使用。
遗憾的是这三个是需要分别配置的,你的问题就在于eclipse的这三个包之间有版本冲突!
你可以上网查一下eclipse的jre配置过程。尽量将eclipse自带的jre更换为官方的,而且版本最好一致!
分享到:
相关推荐
在IT领域,尤其是在Java编程中,遇到“Can not find the main class. Program will exit.”这一错误信息是非常常见的问题。这通常意味着编译器或运行环境无法识别并定位到程序的主类,即包含main方法的类,从而导致...
### "Could Not Find the Main Class, Program Will Exit" 错误解析及解决方法 在Java编程过程中,我们经常会在开发环境中遇到各种各样的错误提示,其中“Could not find the main class, program will exit”是一...
【SpringBoot】Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster报错明细问题解决后记 报错明细 IDEA SpringBoot集成hadoop运行环境,,本地启动项目,GET请求接口触发...
Class.forName("oracle.jdbc.driver.OracleDriver"); // 接下来的代码用于建立数据库连接 } catch (ClassNotFoundException e) { e.printStackTrace(); } } } ``` 一旦驱动注册成功,就可以使用`...
本文将详细介绍如何创建一个JAR文件,并解决在运行过程中遇到的“Could not find the main class, Program will exit”这一错误。 #### 创建JAR文件的基本步骤 1. **准备manifest文件**:首先需要创建一个名为`...
在IDE如Eclipse或IntelliJ IDEA中,可以直接将它们添加到项目的库依赖中。在命令行环境下,可以通过`java -cp`选项指定包含这些JAR的路径。 以下是一个简单的Java发送邮件的示例代码: ```java import javax.mail....
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Could not connect to the database."); e.printStackTrace(); } } } ``` 请注意...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 在这个...
- **Could not find the main class, Program will exit.** - 当遇到这类问题时,通常是因为JAR文件缺少必要的类或库。如果项目中使用了特殊库(如SWT等),则需要进行额外的配置。 4. **处理SWT等特定库的情况**...
因为这样的路径会导致MyEclipse在启动服务器时出现"Could not find the main class"错误。如果遇到此类问题,应立即移动JBoss到一个不含空格的目录。 5. **其他注意事项** - 配置过程中,确保MyEclipse和JBoss的...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 请根据...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Failed to connect to the database."); e.printStackTrace(); } } } ``` 在上述...
- **找不到主类**:如果运行示例程序时遇到错误提示“Could not find the main class:”,需要在MyEclipse中配置正确的JRE路径。具体步骤为:`Window` -> `Preferences` -> `Installed JREs` -> 选择MyEclipse 6.5 ...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 请注意...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 在上述...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 在这个...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 这里,`...
System.out.println("Could not find the driver."); e.printStackTrace(); } catch (SQLException e) { System.out.println("Error connecting to the database."); e.printStackTrace(); } } } ``` 在这个...
- 路径中存在空格会导致MyEclipse在启动服务器时报错:“Could not find the main class”。 - **其他注意事项**: - 在配置过程中确保所有步骤都正确执行。 - 检查JBoss版本与MyEclipse版本兼容性。 - 如果...
- **Error: Could not find or load main class**: - 这个错误通常表明类路径设置不正确。 - 检查`CLASSPATH`环境变量是否包含所有必要的JAR文件。 - 确保项目依赖项已经正确配置。 - **Tomcat启动时出现异常**:...