英文:
A JNI error has occurred, please check your installation and try again.(eventhough Java -version and javac -version also same)
问题
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 the same only. I have also set the classpath in environmental variables. But still, I'm getting the above error. Could anyone provide a solution for this?
英文:
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?
答案1
得分: 0
问题:
java.lang.ClassNotFoundException或java.lang.NoClassDefFoundError意味着在消息中提到的类:org/json/JSONException在类路径上未被JVM找到。
解决方法:
要么,您需要将整个jar添加到您的类路径中
(关于如何做到这一点,请访问:官方Oracle关于将类添加到类路径的文档或将多个jar添加到类路径的5种方法)
要么,如果您使用像Maven这样的构建工具,您可以为缺少的类添加一个依赖:
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
您还可以在此链接中找到整个jar包:用于json依赖的Maven仓库链接。
英文:
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.
专注分享java语言的经验与见解,让所有开发者获益!
评论