Error: A JNI error has occurred, please check your installation and try again

1年前 (2022) 程序员胖胖胖虎阿
500 0 0

java在IDEA编辑的无异常,但是运行时报错: Error: A JNI error has occurred, please check your installation and try again Exception in thread “main”

总共有三种方法:第一种和第二种没有解决,第三种解决了问题。

方法一 有说是java 和 javac版本不一导致的

参考:https://www.codeprj.com/blog/db59fd1.html
错误为发生JNI错误,请检查安装并重试。
  检查原因可以得知是由于javac与java版本不同所致。
  分别使用:

1 javac -version
2 java -version

检查,可以看到如下图结果:
Error: A JNI error has occurred, please check your installation and try again

可以确定报错原因。
  接下来是解决。
  首先进入高级系统设置界面,如下图:
Error: A JNI error has occurred, please check your installation and try again

单击环境变量选项卡,如下图:
Error: A JNI error has occurred, please check your installation and try again

单击系统变量中的Path变量,如下图:
Error: A JNI error has occurred, please check your installation and try again

Error: A JNI error has occurred, please check your installation and try again
可以看到存在两个版本的java,而我目前使用的是%JAVA_HOME%\bin路径,所以将此选项上移到另一个java上方即可,如下图:
Error: A JNI error has occurred, please check your installation and try again
 但需要注意的是,如果Path变量中的第一行为%开头,那么当你再次点击Path选项卡的时候会是类似于下图这种格式的显示:
 Error: A JNI error has occurred, please check your installation and try again

所以为了方便显示系统变量,我们一般让Path变量中的第一行为盘符开头,即可为列表显示:
Error: A JNI error has occurred, please check your installation and try again

点击一系列确定,完成设置,再次实验一开始的编译、运行命令

运行成功,问题解决。

方法二 设置版本和安装版本不一致

参考:https://blog.csdn.net/Mr_xiaodong/article/details/103231835

方法三 IDEA中的运行环境设置问

进入的窗口右上角处,点击进入 Edit Configurations
Error: A JNI error has occurred, please check your installation and try again

运行时有的可以运行,有的不能运行,可以运行的设置中有红框中的参数。
Error: A JNI error has occurred, please check your installation and try again

不能运行的缺失了部分参数
Error: A JNI error has occurred, please check your installation and try again

尝试加入参数:
Error: A JNI error has occurred, please check your installation and try again

添加之后,应用确定。运行程序,运行正常。

相关文章

暂无评论

暂无评论...