问题描述
我正在尝试在我的Java应用程序中制作Microsoft Translator API.我在Windows Azure市场上进行了注册,并注册了Microsoft Translate应用程序,因此我具有这些ClientId和Client Secret密钥,但仍然无法使用.
I'm trying to make Microsoft Translator API in my Java application. I registered in Windows Azure market place and I registered my Microsoft Translate application so I have these ClientId and Client Secret keys but still it doesn't work.
我找不到我做错了.
这是我的代码:
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public class Main {
public static void main(String[] args) {
try{
Translate.setClientId(/* my Client Id */);
Translate.setClientSecret(/* my Client Secret */);
String translatedText = Translate.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
}
}
}
这是我得到的错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONValue
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:161)
at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
at com.memetix.mst.translate.Translate.execute(Translate.java:61)
at dictionary.mainWindow.main(mainWindow.java:27)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONValue
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
Java Result: 1
推荐答案
您在类路径中缺少json-simple.jar: http://search.maven.org/remotecontent?filepath=com/googlecode/json- simple/json-simple/1.1.1/json-simple-1.1.1.jar
You are missing json-simple.jar on your classpath: http://search.maven.org/remotecontent?filepath=com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar
这篇关于Java应用程序中的Microsoft Translator API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!