0

I compiled a java file and tried to launch it with javac but it doesn't work. I tried to update JDK to the newest version, but received this error:

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 
56.0), this version of the Java Runtime only recognizes class file versions up 
to 52.0
It'sNotMe
  • 1,184
  • 1
  • 9
  • 29
  • check the java and javac (compiler) version, Both of them should be in synchronization with each other. – Deep Sep 11 '19 at 18:20
  • javac version - 12.0.2 java version - 1.8.0_221 – Dan Doncenco Sep 11 '19 at 19:49
  • you need to have same compiler and java version in order to run the java class.The UnsupportedClassVersionError arises due to the fact that you have compiled it different version and running it in different version.There are differences between the two version.Can you either try to install previous jdk 8 or compile with target java 8 runtime. You can go through following link: https://stackoverflow.com/questions/11364761/how-do-i-compile-a-java-with-support-for-older-versions-of-java – Deep Sep 12 '19 at 05:33
  • 1
    Thank u javac -source 1.8 -target 1.8 works! – Dan Doncenco Sep 13 '19 at 17:20
  • glad it worked! – Deep Sep 14 '19 at 07:44

1 Answers1

0

When you call java, us the full path to the java executable, as follows:

On Windows:

C:\...\Java12\bin\java.exe my.class

On Linux:

/opt/java12/bin/java my.class

Adjust path according to your environment.

mentallurg
  • 4,967
  • 5
  • 28
  • 36