A jni error has occurred please check your installation and try again ubuntu

Error: A JNI error has occurred, please check your installation and try again - during running Java program from Ubuntu terminal

Questions : Error: A JNI error has occurred, please check your installation and try again - during running Java program from Ubuntu terminal

2022-08-16T17:39:27+00:00 2022-08-16T17:39:27+00:00

739

I'm trying to run a simple client-server anycodings_ubuntu program written in Java through Ubuntu anycodings_ubuntu terminal. I could compile the code anycodings_ubuntu successfully unfortunately, I can't run the anycodings_ubuntu code.

Server class code:

import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public class Server { public static void main(String[] args) { try { //create server Socket with demo port ServerSocket server = new ServerSocket(20); //wait for server connection Socket s = server.accept(); //upon establishing connection, print // successful message System.out.println("connection eastablished"); } catch (IOException e) { e.printStackTrace(); } } }

Client class code:

import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; public class Client { public static void main(String[] args) { try { //create client socket Socket client = new Socket("127.0.0.1", 20); //upon establishing connection, print //successful message System.out.println("connection eastablished"); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }

During running the complied class, I'm anycodings_ubuntu getting the following error:

mamun@mamun:~$ java Test Error: A JNI error anycodings_ubuntu has occurred, please check your anycodings_ubuntu installation and try again Exception in anycodings_ubuntu thread "main" anycodings_ubuntu java.lang.UnsupportedClassVersionError: Test anycodings_ubuntu has been compiled by a more recent version anycodings_ubuntu of the Java Runtime (class file version anycodings_ubuntu 55.0), this version of the Java Runtime anycodings_ubuntu only recognizes class file versions up to anycodings_ubuntu 52.0 at anycodings_ubuntu java.lang.ClassLoader.defineClass1(Native anycodings_ubuntu Method) at anycodings_ubuntu java.lang.ClassLoader.defineClass(ClassLoader.java:763) anycodings_ubuntu at anycodings_ubuntu java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) anycodings_ubuntu at anycodings_ubuntu java.net.URLClassLoader.defineClass(URLClassLoader.java:467) anycodings_ubuntu at anycodings_ubuntu java.net.URLClassLoader.access$100(URLClassLoader.java:73) anycodings_ubuntu at anycodings_ubuntu java.net.URLClassLoader$1.run(URLClassLoader.java:368) anycodings_ubuntu at anycodings_ubuntu java.net.URLClassLoader$1.run(URLClassLoader.java:362) anycodings_ubuntu at anycodings_ubuntu java.security.AccessController.doPrivileged(Native anycodings_ubuntu Method) at anycodings_ubuntu java.net.URLClassLoader.findClass(URLClassLoader.java:361) anycodings_ubuntu at anycodings_ubuntu java.lang.ClassLoader.loadClass(ClassLoader.java:424) anycodings_ubuntu at anycodings_ubuntu sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) anycodings_ubuntu at anycodings_ubuntu java.lang.ClassLoader.loadClass(ClassLoader.java:357) anycodings_ubuntu at anycodings_ubuntu sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

I've tried to search stackoverflow and other anycodings_ubuntu forum and blogs to find a solution, I've anycodings_ubuntu find some similar questions, tried the anycodings_ubuntu answers provided to those question but could anycodings_ubuntu find a solution for my problem. That's why anycodings_ubuntu I'm adding this question here.

Later, I've try to write a very simple Java anycodings_ubuntu program, like just to print a greeting, this anycodings_ubuntu program also could be compiled but would not anycodings_ubuntu run producing the same error. I've tried to anycodings_ubuntu execute the program from different folders anycodings_ubuntu except from the root folder. But all efforts anycodings_ubuntu produce the same result.

public class Test { public static void main(String[] args) { System.out.println("Hello..."); } }

I can perfectly work in Eclipse where my anycodings_ubuntu java version 8, problem occurs only when anycodings_ubuntu working in terminal.

In my Ubuntu jdk version is 11 (which has anycodings_ubuntu been automatically been updated without my anycodings_ubuntu knowledge); My Ubuntu version:18.04.1 LTS

Total Answers 3

31

Answers 1 : of Error: A JNI error has occurred, please check your installation and try again - during running Java program from Ubuntu terminal

The error says it all:

Exception in thread "main" anycodings_ubuntu java.lang.UnsupportedClassVersionError: anycodings_ubuntu Test has been compiled by a more recent anycodings_ubuntu version of the Java Runtime (class anycodings_ubuntu file version 55.0)...

You've compiled for Java 11 ... but anycodings_ubuntu you're running an older JRE (Java 8).

SUGGESTIONS:

  • recompile with -source and -target to anycodings_ubuntu target an earlier version of Java in anycodings_ubuntu your .class file, or

  • Upgrade your target JRE to Java 11

EXAMPLE: javac -target 8 -source 8 anycodings_ubuntu MyClass.java

FYI, these are the Java versions in each anycodings_ubuntu Java class file's header:

https://en.wikipedia.org/wiki/Java_class_file

  • Java SE 11 = 55 (0x37 hex)
  • Java SE 10 = 54 (0x36 hex)
  • Java SE 9 = 53 (0x35 hex)
  • Java SE 8 = 52 (0x34 hex)
  • Java SE 7 = 51 (0x33 hex)
  • Java SE 6.0 = 50 (0x32 hex)
  • Java SE 5.0 = 49 (0x31 hex)
  • JDK 1.4 = 48 (0x30 hex)
  • JDK 1.3 = 47 (0x2F hex)
  • JDK 1.2 = 46 (0x2E hex)
  • JDK 1.1 = 45 (0x2D hex)

Also FYI, here are the command line anycodings_ubuntu options for javac:

Java SE 11 > Tools > javac

PS:

You may have multiple independent anycodings_ubuntu versions of Java installed at the same anycodings_ubuntu time. Use the alternatives command:

  • https://linuxconfig.org/how-to-install-java-on-ubuntu-18-04-bionic-beaver-linux

0

2022-08-16T17:39:27+00:00 2022-08-16T17:39:27+00:00Answer Link

mRahman

3

Answers 2 : of Error: A JNI error has occurred, please check your installation and try again - during running Java program from Ubuntu terminal

I also had this problem. This is my anycodings_ubuntu solution. There was 2 Java versions anycodings_ubuntu installed (java 8 and Java SE anycodings_ubuntu Development kit 13). This error occurs anycodings_ubuntu because of this 2 versions. Just anycodings_ubuntu uninstall old version and you are anycodings_ubuntu done. (*Java compiles .java file using anycodings_ubuntu SE Development kit and trying to execute anycodings_ubuntu using old version. So compatible errors anycodings_ubuntu occurs.)

Then check java versions on cmd using anycodings_ubuntu javac -version and java -version. After anycodings_ubuntu uninstallation, both version codes must anycodings_ubuntu be same.

0

2022-08-16T17:39:27+00:00 2022-08-16T17:39:27+00:00Answer Link

jidam

1

Answers 3 : of Error: A JNI error has occurred, please check your installation and try again - during running Java program from Ubuntu terminal

If you don't want to upgrade your Java anycodings_ubuntu version to Java11. Maybe you can change anycodings_ubuntu the version of neo4j to 3.x. neo4j 3.x anycodings_ubuntu compiled by Java 8, and the neo4j 4.x anycodings_ubuntu compiled by Java 11. Here is the anycodings_ubuntu download site of neo4j community anycodings_ubuntu edition, you can change your version of anycodings_ubuntu neo4j to adjust the local version of anycodings_ubuntu Java anycodings_ubuntu 8. https://neo4j.com/download-center/#community

0

2022-08-16T17:39:27+00:00 2022-08-16T17:39:27+00:00Answer Link

joy

How do I fix JNI error in Ubuntu?

Install Latest Java Update: All newer versions of Java come with backward compatibility. That means a particular version of Java supports all files that require any previous version of Java. So, you just need to install the latest version of Java to fix the JNI error without a second thought.

How do you solve a JNI error has occurred Please check your installation and try again?

This a JNI error has occurred Minecraft server error occurs when you try to start Minecraft or a Minecraft server on a PC that does not have the latest version installed. To fix this, you just need to update your current Java to the latest version.

How do I get rid of JNI error?

In most cases, the JNI error can be fixed simply by updating Java on the device to match the latest release.

How do I choose Java version in Linux?

To check the Java version on Linux Ubuntu/Debian/CentOS:.
Open a terminal window..
Run the following command: java -version..
The output should display the version of the Java package installed on your system. In the example below, OpenJDK version 11 is installed..