起初你或许会认为是一个莫名其妙的错误,因为代码根本一点问题的都没有,可运行期间总是报这个错,比较郁闷。
出现Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 错误的原因,是因为我们使用高版本的JDK编译的Java class文件试图在较低版本的JVM上运行,所报的错误。
因为,高版本的JDK生成的class文件使用的格式,可能与低版本的JDK的.class文件格式不同。这样,低版本的JVM无法解释执行这个.class文件,会抛出Could not find the main class.program will exit,java.lang.UnsupportedClassVersionError不支持的Class版本错误。
这个错误尤其在JDK5与JDK5之前的版本上表现明显。因为,JDK5在Java语法上作了不少增强,引入了一些新的.class文件的元素,导致旧版本的JVM无法解释、执行.class文件。即使这个类并没有使用任何JDK5的新元素,但是JDK5生成的.class文件,JDK1.4及其以前的JVM都无法辨认!
在MyEclipse-->应用服务器下,指定Tomcat5。指定Tomcat使用jdk1.4。这样,就全部指定使用Jdk1.4来编译和运行程序了。如果全部指定jdk5也是可以的。但是,绝对不能够使用jdk5编译程序,而又在jdk1.4上运行程序,那样将会抛出java.lang.UnsupportedClassVersionError不支持的Class版本错误。
这种情况下,不论是Eclipse生成的war包,还是ant文件生成war包,都使用jdk5编译,就会在运行时出现错误,该应用程序将无法启动。如果你查看Tomcat的日志文件,将会看到正是java.lang.UnsupportedClassVersionError错误发生了!
其实无非就是版本问题,JDK版本的问题。
解决方法:在Eclipse窗口(Window)-->首选项(Perferences)-->Java-->编译器(Compiler)-->JDK一致性(JDK Compliance)-->编辑器一致性级别(Complier compliance level),从5.0改到1.4就可以了。
若使用的是更高版本的JDK,则只要相应的改为低版本的就可以了。
分享到:
相关推荐
在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”是一...
NULL 博文链接:https://yintech.iteye.com/blog/374842
### Java打包成JAR文件的方法及解决“Could not find the main class, Program will exit”错误 在Java开发中,将程序打包成一个可执行的JAR文件是非常常见且实用的操作。这种方式不仅便于程序的分发与部署,还能...
java反编译工具jd-gui-1.4.0.jar 可以查看jar包中的.class文件的java代码
- 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....
The API's main purpose is not for transporting, delivering, and forwarding messages; this is the purview of applications such as sendmail and other Mail Transfer Agent (MTA) type programs. MUA-type...
Drag and Drop Component Suite ...If you have registered for update notification via the installation program, you will receive email notification when a new release is available. You will not be notified...
2. **Java Virtual Machine Launcher问题**:若出现"could not find the main class.program will exit."的错误,可能是因为JDK版本过低。Auto_Runner需要1.5及以上版本的JDK。请确保已安装对应版本的JDK。 3. **...
For example, if your header file uses the File class in ways that do not require access to the declaration of the File class, your header file can just forward declare class File; instead of having ...
- **Could not find the main class, Program will exit.** - 当遇到这类问题时,通常是因为JAR文件缺少必要的类或库。如果项目中使用了特殊库(如SWT等),则需要进行额外的配置。 4. **处理SWT等特定库的情况**...
program will present each event to each input node and find out if the input node's filter matches the evidence. If it does match, that fact is printed to standard output, but nothing else is done. ...
4.2 The Timer Class....................................................43 4.2.1 Script Breakdown..........................................45 4.3 Spawn Scripts.............................................
The main advantage of running in-process is that the system usually does not need to perform a context switch. The disadvantage to running in-process is that DLL has access to the process address ...
If the class is not confident in their understanding, review appendix A04_Locking and its accompanying PowerPoint® file. Transactions in SQL Server provide the ACID properties: Atomicity A ...
The availability of drivers that support the features of the specification will simplify the process of developing Windows appli¬cation programs that in-corporate absolute coordinate input, and ...
However, since the request is for IT-related knowledge points from the given information, we will focus on extracting relevant C# concepts and English vocabulary related to IT or programming. ...
The main() is located in lib/gpc.c The top-level loop which iterates over the generations is in generations.c The data structures which you must work with are in the file gpc.h Expressions ...
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; // Set hInstance To NULL } } /* This Code Creates Our OpenGL Window. ...
class, optional commit support on Bochs exit, save/restore file attributes, 1.44 MB floppy support, set file modification date/time - converted the complete hdimage stuff to the new 'hdimage' ...