HTMLUnit不起作用

时间:2013-11-19 12:54:21

标签: java android htmlunit

我已经编写了一个用HTMLUnit登录网站的程序,效果很好。现在我想在我正在构建的Android应用程序中使用它,但它不起作用。我收到了这个错误:

Conversion to Dalvik format failed with error 1

一旦我删除了几个罐子,比如Jetty罐子,我就会遇到这个错误

Could not find class 'com.gargoylesoftware.htmlunit.html.HtmlDivision', referenced from method com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.init

几秒钟后这一个:

11-19 13:47:26.485: E/AndroidRuntime(18991): FATAL EXCEPTION: AsyncTask #1
11-19 13:47:26.485: E/AndroidRuntime(18991): java.lang.RuntimeException: An error occured while executing doInBackground()
11-19 13:47:26.485: E/AndroidRuntime(18991):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.lang.Thread.run(Thread.java:856)
11-19 13:47:26.485: E/AndroidRuntime(18991): Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSCharsetRule
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.lang.Class.getDeclaredMethods(Native Method)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.lang.Class.getDeclaredMethods(Class.java:703)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.processClass(JavaScriptConfiguration.java:444)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.buildUsageMap(JavaScriptConfiguration.java:409)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.<init>(JavaScriptConfiguration.java:365)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(JavaScriptConfiguration.java:381)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.<init>(JavaScriptEngine.java:130)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.WebClient.init(WebClient.java:218)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:193)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:184)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.cofely.VPNProfileLogin.doInBackground(VPNProfileLogin.java:28)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at com.cofely.VPNProfileLogin.doInBackground(VPNProfileLogin.java:1)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-19 13:47:26.485: E/AndroidRuntime(18991):    ... 5 more
11-19 13:47:26.485: E/AndroidRuntime(18991): Caused by: java.lang.ClassNotFoundException: org.w3c.dom.css.CSSCharsetRule
11-19 13:47:26.485: E/AndroidRuntime(18991):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-19 13:47:26.485: E/AndroidRuntime(18991):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-19 13:47:26.485: E/AndroidRuntime(18991):    ... 19 more

有人能说出这里发生了什么吗?感谢

2 个答案:

答案 0 :(得分:1)

看看这个: "Conversion to Dalvik format failed with error 1" on external JAR

不是100%确定这一点,但您可能需要使用以下项目将项目中引用的一些jar转换为dalvik格式:

dx --dex --output="c:\temp\dx.dex" "c:\temp\in.jar"

您可能因为从项目中删除了必要的jar而导致NoClassDefFoundError错误。

答案 1 :(得分:0)

缺少依赖性。您的APK中没有包含org.w3c.dom.css.CSSCharsetRule定义的JAR。

经过短暂的Google搜索,我发现了这个帖子: Getting HtmlUnit to run under Android how to use htmlunit with my android project

如果您需要使用jSoup而不是HtmlUnit,那么重写您的剪贴板似乎要容易得多。