Java执行main方法,异常为:could not find the main class.program will exit

Java执行方法,异常为:could not find the main class.program will exitmain


原因和解决办法如下: 
出现这个错误是由于你的jdk版本与eclipse高版本配置造成的. 
因为我们使用高版本的JDK编译的Java class文件试图在较低版本的JVM上运行,所报的错误。   因为,高版本的JDK生成的class文件使用的格式,可能与低版本的JDK的.class文件格式不同。这样,低版本的JVM无法解释执行这个.class文件,会抛出Could not find the main class.program will exit不支持的Class版本错误。 




解决方法: 
1. 弄清楚该程序是在哪个JDK版本下开发的 
2. 在myEclipse 菜单->Windows->Proferences->java-> Installs  Jres重新设置JDK路径,改为开发程序时的JDK版本(我做到这一步就可以了!我的eclipse是7.0,jdk是6u13的。) 

3. Windows->Proferences->java->Compiler,将compiler compliance level设置为与上面相同的JDK


原文地址:http://rogerfederer.iteye.com/blog/737377

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Version 1.7 ----------- - ADD: Delphi/CBuilder 10.2 Tokyo now supported. - ADD: Delphi/CBuilder 10.1 Berlin now supported. - ADD: Delphi/CBuilder 10 Seattle now supported. - ADD: Delphi/CBuilder XE8 now supported. - ADD: Delphi/CBuilder XE7 now supported. - ADD: Delphi/CBuilder XE6 now supported. - ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now supported. - ADD: Delphi/CBuilder 2010 now supported. - ADD: Delphi/CBuilder 2009 now supported. - ADD: New demo project FlexCADImport. - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond docuemnt wasn't filled when TFlexPanel.DocClipping=True. - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object. - FIX: The result rectangle incorrectly calculated in the TFlexText.GetRefreshRect method. - FIX: Added FPaintCache.rcPaint cleanup in the TFlexPanel.WMPaint method. Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache field moved in the protected class section. Added rcPaint field in FPaintCache that represents drawing rectangle. - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used instead). - FIX: The TFlexRegularPolygon object clones incorrectly drawed in case when TFlexRegularPolygon have alternative brush (gradient, texture). - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFle
Java中,当我们尝试运行一个程序时,如果系统找不到指定的主类,就会出现"could not find the main class:aggressor,aggressor,program will exit"的错误消息。 造成这个错误的原因可能有以下几种情况: 1. 未正确设置程序的入口点:在Java程序中,必须有一个main()方法作为程序的入口点。首先,需要确保程序中有一个main()方法,并且使用了正确的方法签名:public static void main(String[] args)。此外,还需要检查main()方法是否被正确地定义在一个类中。 2. 编译错误:如果程序的源代码存在语法错误或者逻辑错误,那么在编译时就会生成错误的.class文件。当尝试运行这个错误的.class文件时,会出现"could not find the main class"的错误消息。因此,需要仔细检查程序的源代码,确保没有语法错误和逻辑错误。 3. 类路径设置错误:Java程序在运行时需要指定所有所需的类和资源文件的路径。如果类路径设置错误,系统将无法找到主类。在命令行中运行程序时,确保已正确设置类路径。如果使用IDE(集成开发环境)来运行程序,需要检查IDE的项目设置,确认类路径被正确地配置。 4. 缺少所需的classpath文件:有时,当程序依赖于其他库或JAR文件时,可能会出现找不到主类的错误。解决方法是将所需的类库文件或JAR文件添加到类路径中。 总之,出现"could not find the main class:aggressor,aggressor,program will exit"的错误消息表示系统无法找到指定的主类。需要检查程序的入口点是否正确设置,源代码是否存在错误,类路径是否设置正确,并确保所需的类库文件或JAR文件被正确地添加到类路径中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值