尝试通过cmd运行Java代码时出现JNI错误 [英] JNI error when trying to run java code through cmd

查看:57
本文介绍了尝试通过cmd运行Java代码时出现JNI错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译任何Java代码后,当我尝试从cmd运行它时,都会得到以下信息:

After compiling any Java code, when I try run it from cmd I get this:

  Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

我有:

jdk-11.0.1
jre1.8.0_192

我的 PATH 环境中也有 jdk/bin .当我使用IDE并且PC可以识别 java/c -version 命令时,代码可以正常运行.

I also have jdk/bin in my PATH enviroment virable. Code runs fine when I use IDE and my PC recognizes java/c -version command.

推荐答案

类文件版本55.0 表示此.class文件

class file version 55.0 means this .class file is compiled with JDK 11. This file is allowed to run on Java 11 or above, but your java is using that jre1.8.0_192.

您应该更改您的 JAVA_PATH PATH 环境变量,以使命令 java 指向 java <的Java 11版本./code>,例如位于您 jdk-11.0.1 中的一个,或在您的 jdk-11.0.1 java.exe >运行此.class文件.

You should change your JAVA_PATH or PATH environment variable to make the command java points to a Java 11 version of java, for example that one located in your jdk-11.0.1, or use that java.exe inside your jdk-11.0.1 to run this .class file.

这篇关于尝试通过cmd运行Java代码时出现JNI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆