0
java.lang.NoClassDefFoundError: org/json/JSONException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
        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)
        ... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"

The above error occurs whenever i try to run .jar file.java -version and javac -version is same only.I have also set classpath in environmental variables.But still i'm getting the above error.Could anyone provide a solution for this?

Rubini
  • 15
  • 2
  • What part of `Caused by: java.lang.ClassNotFoundException: org.json.JSONException` didn't you understand? – user207421 May 29 '20 at 10:46
  • Share you code along with import packages. – Som May 29 '20 at 10:48
  • Does this answer your question? [A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1](https://stackoverflow.com/questions/22381202/a-jni-error-has-occurred-please-check-your-installation-and-try-again-in-eclips) – Som May 29 '20 at 10:52

1 Answers1

0

Issue: A java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError means that the class mentioned in the message : org/json/JSONException is not found by JVM on the class-path.

Solution: Either, you need to add the whole jar to your class-path (On how to do that, visit : Official Oracle's documentation on adding classes to classpath or 5 ways to add multiple jars to classpath

Or, if you use a build tool like maven, you can add a dependency for the missing class:

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20200518</version>
</dependency>

Also you'll find the whole jar in the link: Maven repo link for json dependency.

Stabak
  • 36
  • 4