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

Java files do not report an error, but Java does report an error when it is run
Take a closer look at the error message
Exception in thread “main” java.lang.UnsupportedClassVersionError: The helloworld has had been compiled by a more recent version of the Java Runtime (class file version 54.0), and this version of the Java Runtime only recognizes the class file versions up to 52.0
Check the cause and find that the Java version is inconsistent with the JavAC version.
Java-version and Javac-Version, indeed
The two versions do not agree
Solution:
1. Query how many Java versions are in Linux

rpm -qa |grep java

2. Then delete them one by one

rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.181-3.b13.el7_5.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.0.el7_4.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 
(Enter rpm --e --nodeps + "existing version of java") Delete as many as you can.

3. Verify that all the original Java versions have been removed

[root@yuan 8-1]# java - version
-bash: /usr/bin/java: No such file or directory

4. Configure newly installed Java environment variables after the original version is removed

vi /etc/profile 

Edit the profile file and add it at the end

JAVA_HOME=/usr/local/java/jdk-10.0.2/   ###(“jdk-10.0.2" is changed to the name of the installation file of the java version you want to install.)
JRE_HOME=$JAVA_HOME/           ###(As there is no jre folder after jdk10 unzip, if it is below jdk10 version, you should
                               for“JRE_HOME=$JAVA_HOME/jre”)
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export JAVA_HOME JRE_HOME PATH CLASSPATH

5. Last update

source /etc/profile

complete

Read More: