HtmlUnit Android 与 WebClient 的问题

发布于 2024-12-02 22:31:22 字数 6061 浏览 1 评论 0原文

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 is amazing, in Java at least I have had no problems with it. Unfortunately when switching the code over to the Android platform, it is giving me errors when I try to create a web-client.

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();
    }
}

Warnings it gives me before the program starts on the AVD.

This is an example of the warning it gives me, this is the exact warning but it is repeated over and over about 100000x times:

 [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.

Is there any help you can give me?

Error in android debugger:

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

**ERROR AFTER ADDING COMMONS-LANG AND REST OF LIBRARY

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゞ花落谁相伴 2024-12-09 22:31:22

我有类似的问题。经过一番研究,我发现这是由于命名空间冲突造成的。您必须重新编译htmlunit的源代码。我现在尝试这样做,但 htmlunit 太大且复杂,我还没有完成。

I have that similar problem. After some research, i found that this is due to namespace conflicts. You must recompile the sourcecode of htmlunit. I try to this now, but the htmlunit is so large and complex that i have not yet completed.

挽心 2024-12-09 22:31:22

您的堆栈跟踪显示抛出了 ExceptionInInitializerError ,其原因是:

Caused by: java.lang.NoClassDefFoundError: org.apache.commons.lang.StringUtils

也许您在类路径中缺少一些 JAR (commons-lang)?

Your stacktrace shows that an ExceptionInInitializerError is thrown and that it is caused by:

Caused by: java.lang.NoClassDefFoundError: org.apache.commons.lang.StringUtils

Perhaps you're missing some JAR (commons-lang) in the classpath?

神妖 2024-12-09 22:31:22

有一个特殊的 Android 版本的 HtmlUnit (https://github.com/HtmlUnit/htmlunit-android)应该可以解决与 android jdk 中不存在的类相关的大多数问题。

页面上还有关于commons-lang问题的提示。

使用此功能还需要将源更新为 HtmlUnit 3 - 请参阅 https://www.htmlunit.org/migration .html 获取一些提示。

There is a special Android version of HtmlUnit (https://github.com/HtmlUnit/htmlunit-android) that should solve most of the issues related to not existing classes in the android jdk.

There is also a hint about the commons-lang problem on the page.

Using this also requires to update your sources to HtmlUnit 3 - see https://www.htmlunit.org/migration.html for some hints.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文