[英]HtmlUnit Android problem with WebClient
HtmlUnit是驚人的,在Java中至少我沒有遇到任何問題。 不幸的是,當將代碼切換到Android平台時,當我嘗試創建Web客戶端時,它會給我錯誤。
import android.app.Activity;
import android.os.Bundle;
import com.gargoylesoftware.htmlunit.WebClient;
public class AndroidTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final WebClient webClient = new WebClient();
}
}
在程序啟動AVD之前它給我的警告。
這是它給我的警告的一個例子,這是確切的警告,但它反復重復約100000次:
[2011-08-31 21:25:24 - AndroidTest] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (org.apache.commons.collections.BeanMap$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.
你有什么幫助可以給我嗎?
android調試器出錯:
09-01 07:44:24.569: WARN/dalvikvm(877): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): FATAL EXCEPTION: main
09-01 07:44:24.600: ERROR/AndroidRuntime(877): java.lang.ExceptionInInitializerError
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.Test.AndroidTestActivity.onCreate(AndroidTestActivity.java:20)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.os.Looper.loop(Looper.java:123)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at java.lang.reflect.Method.invoke(Method.java:521)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at dalvik.system.NativeStart.main(Native Method)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): Caused by: java.lang.NoClassDefFoundError: org.apache.commons.lang.StringUtils
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.gargoylesoftware.htmlunit.util.URLCreator$URLCreatorStandard.toUrlUnsafeClassic(URLCreator.java:66)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.gargoylesoftware.htmlunit.util.UrlUtils.toUrlUnsafe(UrlUtils.java:193)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.gargoylesoftware.htmlunit.util.UrlUtils.toUrlSafe(UrlUtils.java:171)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): at com.gargoylesoftware.htmlunit.WebClient.<clinit>(WebClient.java:162)
09-01 07:44:24.600: ERROR/AndroidRuntime(877): ... 14 more
**添加COMMONS-LANG和其他圖書館后的錯誤
09-02 16:16:34.440: ERROR/AndroidRuntime(396): FATAL EXCEPTION: main
09-02 16:16:34.440: ERROR/AndroidRuntime(396): java.lang.NoClassDefFoundError: com.gargoylesoftware.htmlunit.DefaultCssErrorHandler
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:157)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:180)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at com.Test.AndroidTestActivity.onCreate(AndroidTestActivity.java:21)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.os.Looper.loop(Looper.java:123)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at java.lang.reflect.Method.invoke(Method.java:521)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-02 16:16:34.440: ERROR/AndroidRuntime(396): at dalvik.system.NativeStart.main(Native Method)
我有類似的問題。 經過一些研究,我發現這是由於命名空間沖突造成的。 您必須重新編譯htmlunit的源代碼。 我現在嘗試這個,但是htmlunit是如此龐大和復雜,我還沒有完成。
您的stacktrace顯示拋出了ExceptionInInitializerError
,它是由以下原因引起的:
Caused by: java.lang.NoClassDefFoundError: org.apache.commons.lang.StringUtils
也許你在類路徑中遺漏了一些JAR(commons-lang)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.