0

I am using the Apertium Translator and using the sample code they provide. 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

unhammer
  • 4,306
  • 2
  • 39
  • 52
user2612619
  • 1,119
  • 3
  • 11
  • 28

2 Answers2

2

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..

Or you add a json library to your project path..

zennon
  • 1,080
  • 10
  • 25
  • Using the first download also produces the same error. How do I add the json library to my project path? – user2612619 Aug 24 '13 at 14:55
  • Okay.. Download this json lib https://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar&can=2&q= and add it to your build path.. it should work. The apertium translotar uses this library but it is not added as dependency.. Thats why you get the NoClassDefFoundError.. – zennon Aug 24 '13 at 15:00
  • When I do that the import and the Translate.xxx provides me with errors. – user2612619 Aug 24 '13 at 15:02
  • Thank you, I was removing the old one thinking that the dependency was the only one I was supposed to add. – user2612619 Aug 24 '13 at 15:11
0

Well JVM is not able to find some class at Runtime which was available at compile time. That is the reason of 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.
Both of them related to Java Class Path. I don't know alot about jSON stuff. But you are missing this file org.json.simple.JSONValue you can take it from here http://code.google.com/p/json-simple/
add the above jar file in your class path . And the code will definitely run. Guaranteed.!!!
Thanks

SR-Rehman
  • 83
  • 8