import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public class trans1 {
public static void main(String[] args) throws Exception {
Translate.setClientId("hidden");
Translate.setClientSecret("hidden");
String translatedText = Translate.execute("spiel", Language.GERMAN, Language.FRENCH);
System.out.println(translatedText);
}
}
现在我尝试在Android中使用此功能:
package de.androidnewcomer;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SagHalloActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
Translate.setClientId("hidden");
Translate.setClientSecret("hidden");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
String translatedText = Translate.execute("welt", Language.GERMAN, Language.FRENCH);
Log.i("LOG", translatedText);
} catch (Exception e) {
e.printStackTrace();
}
}
}
但是我得到了这个错误:
09-18 12:53:34.001: E/AndroidRuntime(29488): FATAL EXCEPTION: main
09-18 12:53:34.001: E/AndroidRuntime(29488): java.lang.NoClassDefFoundError: com.memetix.mst.translate.Translate
09-18 12:53:34.001: E/AndroidRuntime(29488): at de.androidnewcomer.SagHalloActivity.onCreate(SagHalloActivity.java:14)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.os.Looper.loop(Looper.java:130)
09-18 12:53:34.001: E/AndroidRuntime(29488): at android.app.ActivityThread.main(ActivityThread.java:3691)
09-18 12:53:34.001: E/AndroidRuntime(29488): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 12:53:34.001: E/AndroidRuntime(29488): at java.lang.reflect.Method.invoke(Method.java:507)
09-18 12:53:34.001: E/AndroidRuntime(29488): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
09-18 12:53:34.001: E/AndroidRuntime(29488): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
09-18 12:53:34.001: E/AndroidRuntime(29488): at dalvik.system.NativeStart.main(Native Method)
有人能帮助我吗?
答案 0 :(得分:3)
您可能需要在 library / lib 文件夹下包含 Jar文件,其中包含com.memetix.mst.language
文件夹,该文件夹可解决此问题。
答案 1 :(得分:0)
你必须将你的代码移动到一个线程
new Thread() {
public void run() {
try {
String translatedText = Translate.execute("welt", Language.GERMAN, Language.FRENCH);
Log.i("LOG", translatedText);`enter code here`
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();