Blog
Let us consider this fibonacci series java program
import java.io.*; public class Fibonacci { public static void main(String args[]) throws IOException { int n1=0,n2=1,n3,i,count; DataInputStream dis=new DataInputStream(System.in); System.out.println("enter the limit:"); count=Integer.parseInt(dis.readLine()); System.out.println(" "+n1); System.out.println(" "+n2); for(i=2;i<count;++i) { n3=n1+n2; System.out.println(" "+n3); n1=n2; n2=n3; } } }
During compilation,
E:\Java-app>javac Fibonacci.java Note: FactorialNumber.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.
Running java program using class file,
E:\Java-app>java Fibonacci Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: FactorialNumber has been compiled by a more recent version of the Java Runtime (class file version 54.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)
We can come to know, the class version error. which means the class file is created using the compiler and runtime environment in machine are not same and compatible.
E:\Java-app>javac --version javac 10.0.2
E:\Java-app>java -version java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
In this environment, javac and java versions are not compatible each other and not same here.
javac version 10.0.2 and javac version 1.8.0_181
To fix the error, search and rename or remove either 1.8.0_181 java file or javac file of 10.0.2 in the environment.
Here we have renamed the 1.8.0_181 compiler file 'java' into 'java-new' in the environment to fix the java JNI UnsupportedClassVersionError error.
Check the complier and java file versions again in the environment once renamed as above for java 1.8.0_181,
E:\Java-app>javac --version javac 10.0.2
E:\Java-app>java -version java version "10.0.2" 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
Let's run the java program again,
E:\Java-app>javac Fibonacci.java Note: FactorialNumber.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. E:\Java-app>java Fibonacci enter the limit: 4 0 1 1 2
Nice this time working fine.
« Previous Next » Blog
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page