简体   繁体   中英

Java: I cannot execute a compiled Java code

C:\Users\YusufGalip\Desktop\JavaDeneme>java deneme
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: deneme 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 52.0

I got this error when i tried to run a compiled program.

It's probably compiled with a more recent version of java than the one you are attempting to use running the program. Do you have multiple versions of Java installed?

Try java -version and javac -version and compare the versions. If you use and IDE/editor where Java is configured in the settings, see that it points to the expected directory.

You've compiled your class with Java 11 (55) while you're still trying to execute/run them using Java-8(52).

Either compile the code using Java-8 or execute with Java-11.

The error clearly says that the compiler version was higher than the JVM version with which you are trying to run. That is why you are getting the error on running.

Java 8 uses major version 52

Java 11 uses major version 55

Reference: https://en.wikipedia.org/wiki/Java_class_file#General_layout

=================

@DO THE FOLLOWING

change your path to point to a more recent version or if you are aware of the version using which the program was compiled, install the version and then execute the same command to run

1) run java -version now 2) Note down the version 3) complete the above @DO **** 4) execute 1) again 5) you should see a different or the latest version 6) run your program :) and you should be able to .... post your results

Finally I solved with your help. There were 2 Java in my computer one of them is "Java SDK Tools 11" and the second one is "Java Runtime 8" I uninstalled the "Java Runtime 8" and it worked.Thank you for your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM