我在 Android 上使用 HtmlUnit 时遇到问题。
protected Boolean doInBackground(Void... params) {
WebClient webClient = new WebClient();
return true;
}
这个简单的代码会导致强制关闭并导致以下错误:
04-15 20:07:28.266: E/dalvikvm(856): Could not find class 'com.gargoylesoftware.htmlunit.WebClient', referenced from method com.synkronus.deeproute.LoginActivity$UserLoginTask.doInBackground
稍后:
04-15 20:07:30.031: E/AndroidRuntime(856): FATAL EXCEPTION: AsyncTask #1
04-15 20:07:30.031: E/AndroidRuntime(856): java.lang.RuntimeException: An error occured while executing doInBackground()
04-15 20:07:30.031: E/AndroidRuntime(856): at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.lang.Thread.run(Thread.java:1096)
04-15 20:07:30.031: E/AndroidRuntime(856): Caused by: java.lang.NoClassDefFoundError: com.gargoylesoftware.htmlunit.WebClient
04-15 20:07:30.031: E/AndroidRuntime(856): at com.synkronus.deeproute.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:204)
04-15 20:07:30.031: E/AndroidRuntime(856): at com.synkronus.deeproute.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:1)
04-15 20:07:30.031: E/AndroidRuntime(856): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-15 20:07:30.031: E/AndroidRuntime(856): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-15 20:07:30.031: E/AndroidRuntime(856): ... 4 more
我的困惑源于“找不到类 'com.gargoylesoftware.htmlunit.WebClient'”错误,即使我已将 HtmlUnit jar 添加到 Eclipse 中的构建路径中并且我可以清楚地看到“缺失”类我的引用库中的文件。