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" java.lang.UnsupportedClassVersionError: Test has been compiled by a more recent version of the Java Runtime (class file version 55.0)...

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

SUGGESTIONS:

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

  • Upgrade your target JRE to Java 11

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

FYI, these are the Java versions in each 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 options for javac:

Java SE 11 > Tools > javac

PS:

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

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