Error in java | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 6

Error in java

I was trying to run a java program with terminal then I faced an error. Java compilation was competed but the problem occurred when I executed `java prog` (prog is the name of my file). Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: prog has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 52.0 Error was lot more big but due to word limit I am unable to give it full. My java compiler version - 12.0.1 My java version - java version "1.8.0_281" Java(TM) SE Runtime Environment (build 1.8.0_281-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode) My complete error > https://code.sololearn.com/cS0lM7l2YE91/?ref=app

31st Jan 2021, 4:37 AM
Krish
Krish - avatar
28 Réponses
+ 6
https://docs.oracle.com/javase/tutorial/getStarted/problems/index.html Read it, this will be helpful for you! NOTE - Name of file and name of class must be same, $ javac helloWorld.java $ java helloWorld.class hello world CODE - public class helloWorld { public static void main(String[] args) { System.out.print("hello world"); }}
31st Jan 2021, 4:43 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 4
Can you please share that program?
31st Jan 2021, 4:40 AM
Atul [Inactive]
+ 3
Thanks Atul for correcting me
31st Jan 2021, 5:37 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 3
https://ibb.co/MRPJb4T my error import java.io.*; public class prog { public static void main(String args[]){ System.out.println("Hello World"); } } and yeah I am doing java prog I get this error by doing java prog.class Error: Could not find or load main class prog.class
31st Jan 2021, 7:54 AM
Krish
Krish - avatar
+ 3
Avinesh Bhai, is correct Krish [less active] ,Java is a compiled language first you have to compile it and after compilation a .class file will be created you have run that class file by writing 'java filename.class' , in terminal. You can take help of YouTube or Google for see it in video.
31st Jan 2021, 10:08 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 3
Solution of JNI Error https://youtu.be/zV4_9O_GoNM https://webdeasy.de/en/error-a-jni-error-has-occured-how-to-fix-this-java-error/ The problem occurs because your JRE (Java Runtime Enviroment) and your JDK (Java Development Kit) are not working together correctly. Usually the problem occurs when you want to call a . jar file by comment line, e.g. with the command java -jar File. jar . see this site and video, I copied a part of para from The site! All the best!
31st Jan 2021, 10:46 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 2
Atul It's hello world I was first time using terminal to run java so I first tested it with hello world
31st Jan 2021, 4:42 AM
Krish
Krish - avatar
+ 2
Krish [less active] you were using sololearn or any other JDK?
31st Jan 2021, 4:55 AM
Atul [Inactive]
+ 2
Rishav Tiwari I think so you have missed out String args[]
31st Jan 2021, 4:58 AM
Atul [Inactive]
+ 2
Rishav Tiwari My pleasure
31st Jan 2021, 5:40 AM
Atul [Inactive]
+ 2
Krish [less active] have you read that site! Please post the image of your code! And image of terminal too! So it will be easy to justify error
31st Jan 2021, 6:24 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 2
NOTE - 1) Give space after string 2) first compile your program, by writing $ javac filename.java After compling a class file will be created , and type $ java filename.class Don't forget to give extension of .class while running!
31st Jan 2021, 8:00 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 2
Basically your program is coming under runtime errors.
31st Jan 2021, 8:16 AM
Atul [Inactive]
+ 2
Atul i don't have anything in my program how would I get runtime error?
31st Jan 2021, 9:12 AM
Krish
Krish - avatar
+ 2
You must compile your code first javac prog.java To execute java prog
31st Jan 2021, 9:42 AM
Avinesh
Avinesh - avatar
+ 2
Rishav Tiwari and Avinesh I executed > javac prog.java > java prog
31st Jan 2021, 10:12 AM
Krish
Krish - avatar
+ 2
Rishav Tiwari > java prog.class Gives an error which is could not find or load main class prog.class And also in web tutorials it says not to add class extension
31st Jan 2021, 10:27 AM
Krish
Krish - avatar
+ 2
Krish [less active] , bro please send me what you are doing from starting to end as a video ūü§Į ! If you don't mind
31st Jan 2021, 10:31 AM
AbhiyantńĀ
AbhiyantńĀ - avatar
+ 2
Rishav Tiwari you don't add .class after file name to execute the code. It will not work. I have already mentioned how to execute in my last comment.
31st Jan 2021, 10:33 AM
Avinesh
Avinesh - avatar
+ 2
Avinesh Oh! My bad! ūüėÖ
31st Jan 2021, 10:37 AM
AbhiyantńĀ
AbhiyantńĀ - avatar