Why do I get LinkageError when only one version of Java seems to be available?
Solution 1
The problem is that the other downloaded versions of Java are reachable via my PATH variable. So after specifying the full path to the javac and java executables when compiling and executing my program it works.
Solution 2
I got this error in eclipse:
LinkageError occurred while loading main class com.example.demo.SpringDemo1Application
java.lang.UnsupportedClassVersionError: com/example/demo/SpringDemo1Application has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0
- Right Click on Project Name
- Select Properties
- select Java Compiler
- Click on Restore Defaults.
- Apply and close.
This works for me. enter image description here
Solution 3
use with sudo command for update-alternatives --config javac
and update-alternatives --config java
. So, you can choose the same version of java for compiler and runtime environment.
I have also got same error after compiling my java program. I have screenshot ---->
Chris Anderson
Updated on February 16, 2022Comments
-
Chris Anderson about 2 years
This is my Java environment:
~: java -version java version "11.0.1" 2018-10-16 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
But when trying to execute a program after compiling it I get the following error:
Error: LinkageError occurred while loading main class ClassName java.lang.UnsupportedClassVersionError: ClassName has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 54.0
My PATH and JAVA_HOME variables both point to this version of java. I have other versions downloaded but it seems they are not registered in the system:
update-alternatives --display java java - auto mode link best version is /usr/lib/jvm/java-11-openjdk-amd64/bin/java link currently points to /usr/lib/jvm/java-11-openjdk-amd64/bin/java link java is /usr/bin/java slave java.1.gz is /usr/share/man/man1/java.1.gz /usr/lib/jvm/java-11-openjdk-amd64/bin/java - priority 1101 slave java.1.gz: /usr/lib/jvm/java-11-openjdk-amd64/man/man1/java.1.gz
So how come the compilation and execution are done with different versions?
-
JGlass over 5 yearsGlad it worked for you! With JBoss, I always hard code the path as it relies on specific java versions and our sys admins can't always be trusted to not update the java which would wreak havoc in production ;-)
-
BugsOverflow almost 2 yearsThis worked for me but to improve it a little, if you need an specific version you can also select it from the dropdown menus "generated .class files compatibility" and "source compatibility"