java.lang.UnsupportedClassVersionError [Resolved]




Recently i installed latest version of java SDK on 64-bit Windows 10 OS. I wrote a small java program, I was able to compile the program, but when i ran the program ,i got below error.

Error: A JNI Error has occured, please check your installation and try again

Exception in thread “main” java.lang.UnsupportedClassVersionError: main/Main has been compiled by a more recent version of the Java Runtime……….

 

After i googled it for a while, i got to know that the Java Run time version was old on my PC. when i compiled the java file, It created a class file whose version was old.  So, i did below steps and it fixed java.lang.UnsupportedClassVersionError.

  1. Uninstall the old versions of java (JRE or JDK).
  2. Install latest Java
  3. On Windows, Open Control Panel open-control-panel-using-windows-start-button
  4. Goto System and Security system-and-security-on-control-panel
  5. Goto Systems system-settings-control-panel
  6. Goto Advanced system Settingsadvanced-system-settings-on-control-panel
  7. Click on Environment Variables…Environment-variables-on-system-properties-window
  8. In User Variables and System Variables, i changed the values for JAVA_HOME and JRE_HOME. (in my case, i changed them to latest installed path C:\Program Files\Java\jre1.8.0_221)java-user-variables-path-on-environment-variables-windowjava-system-variables-path-on-environment-variables-window
  9. Make sure, the Path variable in System Variables has C:\Program Files\Java\jdk-xx.x.x\bin where xx.x.x is the JDK version that you installed.path-system-variable-on-environment-variables
  10. After making above changes, click OK, OK until you close all opened windows.
  11. Open Command Prompt
  12. Run java -version
  13. Run javac -versionchecking-java-version-on-command-prompt-window
  14. java and javac versions should match, otherwise restart PC and recheck the versions. If they match, you can go and run the java program file without getting any java.lang.UnsupportedClassVersionError error.

Above steps fixed the error for me. Hope it also helps you.

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published. Required fields are marked *