不支持的类版本错误

发布于 2024-07-29 17:44:52 字数 1226 浏览 6 评论 0原文

我正在尝试使用 PuTTY 运行一些 Java 代码。 我在一个文件夹中有我需要的所有 jar 文件,当在带有“classname.class”文件夹的文件夹中时,我尝试运行该文件,但出现以下错误。

Exception in thread "main" java.lang.UnsupportedClassVersionError: dueDate (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:489)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:104)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:245)
        at java.net.URLClassLoader.access$1(URLClassLoader.java:211)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:192)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:290)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)

我不知道这个错误意味着什么以及我应该如何修复它。 我使用 Eclipse 和jdk-6u14对其进行编程。

PuTTY 使用的是 Java 版本“1.2.2”,

如何更改它以使用较新版本的 Java?

I am trying to run some Java code using PuTTY. I have all the jar files I need in a folder and when in the folder with the 'classname.class' folder I try to run the file but I get the following error.

Exception in thread "main" java.lang.UnsupportedClassVersionError: dueDate (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:489)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:104)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:245)
        at java.net.URLClassLoader.access$1(URLClassLoader.java:211)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:192)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:290)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)

I don't know what this error means and how I should go about fixing it. I used Eclipse to program it and jdk-6u14.

PuTTY is using Java version '1.2.2'

How do you cange it to use a newer version of Java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

十六岁半 2024-08-05 17:44:52

嗯,PuTTY 并不是真正使用 Java 的。 这是您要连接的服务器。 PuTTY 正是您用来连接该服务器的工具。

您有两个选择:

  • 将 Java 的目标版本(Windows/Preferences/Java/Compiler/Compiler Compiler Compiler Level)更改为 1.3...理想情况下,您也应该针对 1.2.2 JDK 进行编译,以避免使用任何以下类:不会出现在服务器上。
  • 在服务器上获取更新版本的 Java。

后者可能更难,但要好得多。 您确实不想将自己限制在 Java 1.2.2 上。

Well it's not really PuTTY that's using Java. It's the server you're connecting to. PuTTY is just what you're using to conenct to that server.

You have two options:

  • Change the target version of Java (Windows/Preferences/Java/Compiler/Compiler Compliance Level) to 1.3... ideally you should compile against a 1.2.2 JDK as well, in order to avoid using any classes which won't be present on the server.
  • Get hold of a more up-to-date version of Java on the server.

The latter is likely to be harder but much better. You really don't want to have to restrict yourself to Java 1.2.2.

黎歌 2024-08-05 17:44:52

您正在尝试在非常旧的 JDK 上运行新的 java 代码 - 1.2.2

Eclipse 可能会提供一些向后编译选项(检查您的项目 -> 首选项 -> java 编译器),尽管我认为它只能返回到 1.3 。

因此,您可能想尝试使用较新的 JDK 来实际运行代码。

You're trying to run new java code on a really old JDK - 1.2.2

Eclipse might provide some backwards-compilation options (check your project -> preferences -> java compiler), though I think it only goes back to 1.3.

Therefore you might want to try using a newer JDK to actually run the code.

她比我温柔 2024-08-05 17:44:52

该错误表明您正在尝试在不支持类的 JVM 上运行类。 该类版本 49.0 是在 Java 5 中引入的。该版本之前的 JRE 不支持它们。

The error suggests that you are trying to run classes on a JVM that does not support them. The class version 49.0 was introduced in Java 5. JREs before that version will not support them.

つ低調成傷 2024-08-05 17:44:52

UnsupportedClassVersion 意味着已编译的类是使用比您尝试运行它更高版本的 JVM 编译的。 最后几个主要版本是java 1.6==50.0、java1.5==49.0、java1.4==48.0。

顺便说一句,您可以设置 eclipse 来编译该类的早期版本,尽管我不确定您是否可以回溯到 1.22- Project:Properties:Compiler:CompilerComplianceLevel。

UnsupportedClassVersion means the compiled class was compiled with a later version of the JVM than you're trying to run it with. The last few major versions are java 1.6==50.0, java1.5==49.0, java1.4==48.0.

BTW, you can set eclipse to compile an earlier version of the class, although I'm not sure you can go back as far as 1.22- Project:Properties:Compiler:CompilerComplianceLevel.

要走就滚别墨迹 2024-08-05 17:44:52

这基本上意味着您正在尝试运行使用该版本 JVM 不支持的功能的代码。 您的服务器的 JVM 版本比您在 Eclipse 中使用的版本旧。 尝试将服务器 JVM 升级到最新版本。

It basically means you are trying to run code that is using features that are not supported on that version of the JVM. Your server has an older JVM version than what you are using in your eclipse. Try upgrading your server JVM to the most up to date version possible.

妳是的陽光 2024-08-05 17:44:52

早些时候,当我尝试使用命令

java -jar <jarfilename> --http <portname> --id <id name>

来运行和演示 DHT 独立项目时,我遇到了同样的问题。
问题出在 EC2 实例设置上,并且存在于 JAVA 版本中。
所以你需要做的就是更新版本。 我不敢相信两次相近的更新会有如此大的差异,但该命令在 JAVA1.7 中不起作用,因此我将其更新到 JAVA 1.8。
运行这些命令来执行以下删除和安装新版本

sudo yum install java-1.8.0

,然后

sudo yum remove java-1.7.0-openjdk

记住首先安装版本 1.8,然后删除 1.7。
然后我希望你的问题能够得到解决

I was having the same issue earlier when I was trying to use command

java -jar <jarfilename> --http <portname> --id <id name>

to run and demonstrate a DHT standalone projects.
The issue is with the EC2 instances settings and it resides in JAVA version.
So all you need to do is to update the version. I can't believe that there could be such difference in two close updates, but the command doesn't work in JAVA1.7 and hence I updated it to JAVA 1.8.
Run these commands to do the following removing and installing new version

sudo yum install java-1.8.0

and then

sudo yum remove java-1.7.0-openjdk

Remember first install version 1.8 and then remove 1.7.
And then i hope your issue would be resolved

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文