我正在尝试在Android中测试这个api:http://code.google.com/p/google-api-spelling-java/。我创建了一个新的应用程序并将库和依赖项从prev url复制到项目的“libs”目录,然后通过Java Build Path-> Libraries-> Add jar ...添加对它们的引用...
这是测试活动:
package com.jimmcgowen.googleapispelling;
import org.xeustechnologies.googleapi.spelling.SpellChecker;
import org.xeustechnologies.googleapi.spelling.SpellCorrection;
import org.xeustechnologies.googleapi.spelling.SpellResponse;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("classpath", System.getProperty("java.class.path") );
}
public void onDoIt(View view) {
EditText input = (EditText)findViewById( R.id.PlainText );
String word = input.getText().toString().trim();
SpellChecker checker = new SpellChecker();
SpellResponse spellResponse = checker.check( word );
for (SpellCorrection sc : spellResponse.getCorrections()) {
Log.i("Spell Checker", sc.getValue());
TextView tv = new TextView( this );
tv.setText( sc.getValue() );
LinearLayout container = (LinearLayout)findViewById( R.id.ResultContainer );
container.addView( tv );
}
}
}
哪个编译好,但是当我运行它时,我得到:
07-22 16:16:48.673: E/dalvikvm(29209): Could not find class 'org.xeustechnologies.googleapi.spelling.SpellChecker', referenced from method com.jimmcgowen.googleapispelling.MainActivity.onDoIt
07-22 16:16:48.703: W/dalvikvm(29209): VFY: unable to resolve new-instance 28 (Lorg/xeustechnologies/googleapi/spelling/SpellChecker;) in Lcom/jimmcgowen/googleapispelling/MainActivity;
07-22 16:16:48.713: D/dalvikvm(29209): VFY: replacing opcode 0x22 at 0x0015
07-22 16:16:48.713: D/dalvikvm(29209): VFY: dead code 0x0017-004c in Lcom/jimmcgowen/googleapispelling/MainActivity;.onDoIt (Landroid/view/View;)V
07-22 16:16:48.903: I/classpath(29209): .
07-22 16:16:48.903: D/ATRecorder(29209): com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@40529128
07-22 16:16:53.948: D/AndroidRuntime(29209): Shutting down VM
07-22 16:16:53.958: W/dalvikvm(29209): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
07-22 16:16:53.978: E/AndroidRuntime(29209): FATAL EXCEPTION: main
07-22 16:16:53.978: E/AndroidRuntime(29209): java.lang.IllegalStateException: Could not execute method of the activity
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.view.View$1.onClick(View.java:2192)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.view.View.performClick(View.java:2533)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.view.View$PerformClick.run(View.java:9299)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.os.Handler.handleCallback(Handler.java:587)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.os.Handler.dispatchMessage(Handler.java:92)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.os.Looper.loop(Looper.java:150)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.app.ActivityThread.main(ActivityThread.java:4352)
07-22 16:16:53.978: E/AndroidRuntime(29209): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 16:16:53.978: E/AndroidRuntime(29209): at java.lang.reflect.Method.invoke(Method.java:507)
07-22 16:16:53.978: E/AndroidRuntime(29209): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
07-22 16:16:53.978: E/AndroidRuntime(29209): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
07-22 16:16:53.978: E/AndroidRuntime(29209): at dalvik.system.NativeStart.main(Native Method)
07-22 16:16:53.978: E/AndroidRuntime(29209): Caused by: java.lang.reflect.InvocationTargetException
07-22 16:16:53.978: E/AndroidRuntime(29209): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 16:16:53.978: E/AndroidRuntime(29209): at java.lang.reflect.Method.invoke(Method.java:507)
07-22 16:16:53.978: E/AndroidRuntime(29209): at android.view.View$1.onClick(View.java:2187)
07-22 16:16:53.978: E/AndroidRuntime(29209): ... 11 more
07-22 16:16:53.978: E/AndroidRuntime(29209): Caused by: java.lang.NoClassDefFoundError: org.xeustechnologies.googleapi.spelling.SpellChecker
07-22 16:16:53.978: E/AndroidRuntime(29209): at com.jimmcgowen.googleapispelling.MainActivity.onDoIt(MainActivity.java:29)
07-22 16:16:53.978: E/AndroidRuntime(29209): ... 14 more
请注意,classpath在运行时为空。我认为这就是问题所在,但我不确定从哪里开始。
使用API级别8 SDK工具20 平台工具13 我刚刚更新了eclipe插件。
答案 0 :(得分:0)
将jar添加到资产文件夹,然后将它们链接到项目构建路径。别忘了在订单和导出标签中选择罐子。