简体   繁体   English

翻译时的java.lang.NoClassDefFoundError

[英]java.lang.NoClassDefFoundError when Translating

I am using the Apertium Translator and using the sample code they provide. 我正在使用Apertium Translator并使用他们提供的示例代码。 My code is like this. 我的代码是这样的。

import com.robtheis.aptr.language.Language;
import com.robtheis.aptr.translate.Translate;

public class Test {

public static void main(String[] args) throws Exception {
    // Set the Apertium API Key - Get yours at http://api.apertium.org/register.jsp
    Translate.setKey("BNSCFhEL8DoTApc2I1+aa3UYkVg");

    String translatedText = Translate.execute("Hola, mundo!", Language.SPANISH, Language.ENGLISH);

    System.out.println(translatedText);
}
}

I have no errors or warnings and when I run the program I get the following errors. 我没有错误或警告,当我运行程序时,我得到以下错误。

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONValue
at com.robtheis.aptr.ApertiumTranslatorAPI.jsonSubObjToString(ApertiumTranslatorAPI.java:195)
at com.robtheis.aptr.ApertiumTranslatorAPI.retrieveSubObjString(ApertiumTranslatorAPI.java:140)
at com.robtheis.aptr.translate.Translate.execute(Translate.java:56)
at maple.Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONValue
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)
... 4 more

The .jar I'm using is the second one from https://github.com/rmtheis/apertium-translator-java-api/downloads 我正在使用的.jar是第二个来自https://github.com/rmtheis/apertium-translator-java-api/downloads

You have to download the first one. 你必须下载第一个。 The first jar file ( apertium-translator-java-api-0.2-jar-with-dependencies.jar ) contains the all dependencies needed.. 第一个jar文件( apertium-translator-java-api-0.2-jar-with-dependencies.jar )包含所需的所有依赖项。

Or you add a json library to your project path.. 或者您将json库添加到项目路径中。

Well JVM is not able to find some class at Runtime which was available at compile time. 好吧JVM无法在运行时找到一些在编译时可用的类。 That is the reason of NoClassDefFoundError 这就是NoClassDefFoundError的原因
Below you also have ClassNotFoundException for this class org.json.simple.JSONValue which means you are trying to load the particular class at run-time by name. 下面你还有这个类org.json.simple.JSONValue的 ClassNotFoundException ,这意味着你试图在运行时按名称加载特定的类。
Both of them related to Java Class Path . 它们都与Java Class Path有关 I don't know alot about jSON stuff. 我不太了解jSON的东西。 But you are missing this file org.json.simple.JSONValue you can take it from here http://code.google.com/p/json-simple/ 但是您缺少此文件org.json.simple.JSONValue,您可以从这里获取它http://code.google.com/p/json-simple/
add the above jar file in your class path . 在类路径中添加上面的jar文件。 And the code will definitely run. 代码肯定会运行。 Guaranteed.!!! 保证。!!!
Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM