首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >翻译时的java.lang.NoClassDefFoundError

翻译时的java.lang.NoClassDefFoundError
EN

Stack Overflow用户
提问于 2013-08-24 14:46:38
回答 2查看 1.7K关注 0票数 0

我使用的是阿珀腾翻译器和他们提供的示例代码。我的密码是这样的。

代码语言:javascript
复制
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);
}
}

我没有错误或警告,当我运行程序时,我会得到以下错误。

代码语言:javascript
复制
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

我使用的.jar是来自https://github.com/rmtheis/apertium-translator-java-api/downloads的第二个

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-24 14:51:55

你必须下载第一个。第一个jar文件(apertium-translator-java-api-0.2-jar-with-dependencies.jar)包含所需的所有依赖项。

或者在项目路径中添加一个json库。

票数 2
EN

Stack Overflow用户

发布于 2013-08-24 15:29:59

JVM无法在运行时找到在编译时可用的类。这就是NoClassDefFoundError的原因

下面还有这个类的ClassNotFoundException,这意味着您试图在运行时按名称加载特定的类。

它们都与Java类路径相关。我对jSON的东西不太了解。但是你丢失了这个文件org.json.simple.JSONValue你可以从这里拿走它http://code.google.com/p/json-simple/

在类路径中添加上述jar文件。代码肯定会运行。保证!

谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18419777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档