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.
- Uninstall the old versions of java (JRE or JDK).
- Install latest Java
- On Windows, Open Control Panel
- Goto System and Security
- Goto Systems
- Goto Advanced system Settings
- Click on Environment Variables…
- 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)
- 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.
- After making above changes, click OK, OK until you close all opened windows.
- Open Command Prompt
- Run java -version
- Run javac -version
- 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.