java在编译后出现 Error: A JNI error has occurred, please check your installation and try again

   今天写代码的时候突然在运行的时候出了一个从来没发生过的问题

 

   在运行Java(windows环境下)程序,javac运行.java文件没有报错,但java运行的时候报错

java在编译后出现 Error: A JNI error has occurred, please check your installation and try again_第1张图片

java在编译后出现 Error: A JNI error has occurred, please check your installation and try again_第2张图片

    看到这个报错后试过很多方法,都没效果,甚至还专门跑去看了下java和javac的版本是否一致

java在编译后出现 Error: A JNI error has occurred, please check your installation and try again_第3张图片

   看了java和javac的版本,发现没问题,项目也没问题就一个简单的hellojava输出就报错了,这是为什么呢。然后我又仔细看了这个报错的信息,看到了这句话:Exception in thread "main" java.lang.UnsupportedClassVersionError: hello has been compiled by a more recent version of the Java Runtime (class file version 56.0),大概意思是:线程“main”java.lang.UnsupportedClassVersionError中出现异常:hello已由java运行时的最新版本。

   于是想了下应该是eclipse中设置的java版本和安装的版本不匹配。

java在编译后出现 Error: A JNI error has occurred, please check your installation and try again_第4张图片

java在编译后出现 Error: A JNI error has occurred, please check your installation and try again_第5张图片

java在编译后出现 Error: A JNI error has occurred, please check your installation and try again_第6张图片

右键项目选最后面一个properties,找到JavaCompiler更换为和安装的java版本即可解决问题。如果我的问题也帮到了你,那么我的付出是值得的!

你可能感兴趣的:(java在编译后出现 Error: A JNI error has occurred, please check your installation and try again)