简体   繁体   English

Eclipse运行功能不起作用:不支持的major.minor版本

[英]Eclipse run function not working: unsupported major.minor version

When I try to run a Java program in Eclipse on one of my computers, I get this error: 当我尝试在一台计算机上的Eclipse中运行Java程序时,出现以下错误:

Exception in thread "main" java.lang.UnsupportedClassVersionError: gameLogics/Game : Unsupported major.minor version 51.0

at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I searched the internet and found multiple solutions, but they all just said that I was trying to run it with an older version of Java than I compiled it with. 我在互联网上搜索并找到了多种解决方案,但是他们都说我正在尝试使用比我编译过的Java更旧的版本来运行它。 The only solution was to re-download Java or set the compliance level of Eclipse to 1.6, neither of which worked for me. 唯一的解决方案是重新下载Java或将Eclipse的遵从性级别设置为1.6,这两种方法都不适合我。 (The compliance level one did not work because I used some features only available in Java 7. I did use it before and it worked, but I required some features from Java 7.) (合规性级别1无效,因为我使用了Java 7中仅提供的某些功能,我曾经使用过并且可以使用,但是我需要Java 7中的某些功能。)

Curiously, the project works perfectly on my other computer using exactly the same files, including preference files and application data. 奇怪的是,该项目可以使用完全相同的文件(包括首选项文件和应用程序数据)在我的另一台计算机上完美运行。 It also works if I export it on either computer, so only Eclipse's run feature seems to be broken. 如果我将其导出到任何一台计算机上,它也可以工作,因此似乎只有Eclipse的运行功能坏了。

I have not provided any code because there is no single relevant part, so I would have to upload all of my code. 我没有提供任何代码,因为没有单个相关的部分,因此我必须上载所有代码。

Is there any solution for this that is not one of the ones that I mentioned earlier in this post? 有什么解决方案不是我在本文前面提到的解决方案之一吗?

EDIT: Both of my computers are Macs if it is important. 编辑:如果重要的话,我的两台计算机都是Mac。

Two options: 两种选择:

  1. It's a path issue: See: Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0) 这是一个路径问题:请参阅: 线程“主”中的异常java.lang.UnsupportedClassVersionError:a(不受支持的major.minor版本51.0)
  2. You need to rebuild the class files. 您需要重建类文件。

Have you tried rebuilding your project? 您是否尝试过重建项目? I would suggect to CLEAN and REBUILD. 我建议进行清洁和重建。 If this doesn't work, go to the bin folder and delete everything inside. 如果这不起作用,请转到bin文件夹并删除其中的所有内容。 I suspect that eclipse is not cleaning the old .class files from the other computer. 我怀疑Eclipse无法从另一台计算机清除旧的.class文件。

If this doesn't work see the link as it may be a path issue. 如果这不起作用,请查看链接,因为它可能是路径问题。 As another post says: 如另一篇文章所述:

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime. 发生java.lang.UnsupportedClassVersionError的原因是,编译时JDK较高,而运行时JDK较低。

So, you need to check your settings and paths. 因此,您需要检查您的设置和路径。 Most likely you may be compiling and running with different JDK versions/levels. 您很有可能正在使用不同的JDK版本/级别进行编译和运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM