A JNI error has occurred, please check your installation and try again problem fix 2021

Hi, This is a common problem when you want to run a java program using the command line. The problem is occurring for so many reasons. Most of the cause is the different versions of the Java JDK and the Java JRE versions.

I have been having this problem for a while, but now I have figured it out.

It turns out that Java JDK 15 have both the JRE and the JDK inside the bin folder of the Java 15 JDK. (I have always believed that JRE and JDK are different application, but it turns out things have changed)

My problem was that I had Java JDK 15 installed on my computer

At the same time, I had Java 8 (JRE) Installed on my computer.

So my computer is getting confused.

The error looks like:

Error: A JNI error has occurred, please check your installation and try again
 Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of
 the Java Runtime (class file version 59.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)

Solution:

With my command prompt environment setup to run Java and Javac commands:

I typed the follow commands:

java -version  

// this gave me Java 8

After that, I typed:

javac -version

// this gave me Java 15

a jni error has occurred please check your installation and try again exception in thread main

In other words, my program is getting compiled with Java 15 and I am trying to run with Java 8.

To solve the problem, I uninstalled Java 8 JRE from my computer.

Went back to command prompt to check if “java -version” and “javac -version” is returning the same version number, and yes, it is returning Java 15.

a jni error has occurred please check your installation and try again exception in thread main

Tried recompiling my program again, and running it. It Worked!!

a jni error has occurred please check your installation and try again exception in thread main

Wow! Its work fine. If not then comment……

Leave a Reply