get this error when i want to run compiled class java.lang.UnsupportedClassVersionError

153 views Asked by At

I'm on Fedora 36 and installed java-latest-openjdk-devel (OJDK19) from Fedora repositories.

I wrote a simple print hello world and named it test_for_error as follows

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

then i tried to compile and run using javac & java commands

➤ javac test_for_error.java 

➤ java test_for_error
Error: LinkageError occurred while loading main class test_for_error
    java.lang.UnsupportedClassVersionError: test_for_error has been compiled by a more recent version of the Java Runtime (class file version 63.0), this version of the Java Runtime only recognizes class file versions up to 61.0

I expected to get the hello world as output, but facing the above error.

Where's the problem, and how should I solve it?

1

There are 1 answers

0
Naadiyaar On BEST ANSWER

So as friends mentioned, I checked/compared javac(JDK) & java(JRE) versions and as you see my system was using an older JRE than which I installed and expected to be default

➤ javac -version
javac 19.0.1

➤ java -version
java 17.0.5

then i changed to my preferred version using this command:

sudo update-alternatives --config java

source: https://www.xmodulo.com/change-default-java-version-linux.html

so i tried again and:

➤ java test_for_error
Hello, World!