I am learning Java and trying some code on Thread. I made a program using Thread class and it is compiling fine, but when I run the program it is giving the error. The complete error is:
Error: A JNI error has occurred, please check your installation and
try again
Exception in thread "main"
java.lang.UnsupportedClassVersionError: Main has been compiled by a
more recent version of the Java Runtime (class file version 53.0),
this version of the Java Runtime only recognizes class file versions
up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
My thread java file is:
import java.lang.Thread;
class MyThread extends Thread
{
private String s;
public MyThread(String s)
{
this.s = s;
}
public void run()
{
System.out.println(s);
}
}
And my java file with main function is: import java.util.Scanner;
class Main
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s1, s2;
System.out.print("Enter string for first thread: ");
s1 = scanner.nextLine();
System.out.print("Enter string for second thread: ");
s2 = scanner.nextLine();
MyThread t1 = new MyThread(s1);
MyThread t2 = new MyThread(s2);
t1.start();
t2.start();
scanner.close();
}
}
My OS is Windows 10 Home. I compiled the file using javac Main.java
and tried running the compiled .class file with java Main
. What is the reason of the error? How can I prevent it?