Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法 .
2011-08-20 09:44
941 查看
转载于:http://blog.csdn.net/wangcheng8080/article/details/2492265
起初你或许会认为是一个莫名其妙的错误,因为代码根本一点问题的都没有,可运行期间总是报这个错,比较郁闷。
出现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窗口-->首选项-->Java-->编译器-->JDK一致性-->编辑器一致性级别,从5.0改到1.4就可以了。
起初你或许会认为是一个莫名其妙的错误,因为代码根本一点问题的都没有,可运行期间总是报这个错,比较郁闷。
出现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窗口-->首选项-->Java-->编译器-->JDK一致性-->编辑器一致性级别,从5.0改到1.4就可以了。
相关文章推荐
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法 .
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 错误的解决办法
- Eclipse 运行项目抛UnsupportedClassVersionError弹出yunCould not find the main class.program will exit
- 解决运行java application时提示Could not find the main class.Program will exit.问题
- java调用本地方法的时候报错 could not find the main class:xx.program will exit
- java打jar包的异常一:could not find the main class,java.lang.UnsupportedClassVersionError: Bad version numb
- Java执行main方法,异常为:could not find the main class.program will exit
- 【解决方法】Could not find the main class Program will exit
- Java执行main方法,异常为:could not find the main class.program will exit
- 解决java virtual machine launcher could not find the main class. program will exit
- could not find the main class. program will exit问题的解决方法
- @(报错)could not find the main class, Program will exit(已解决)
- (报错)could not find the main class, Program will exit(已解决)
- Could not find the main class program will exit的终极解决办法,神坑
- could not find the main class, Program will exit(已解决)