在Android Studio项目中使用htmlunit时,没有类型为Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier的静态字段INSTANCE [英] No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier when using htmlunit in Android Studio Project

查看:1042
本文介绍了在Android Studio项目中使用htmlunit时,没有类型为Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier的静态字段INSTANCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android Studio项目中使用htmlunit 2.36.0.我已经成功编译了apk,但是当我尝试获取网页时却遇到了运行时错误. 以前,我遇到以下错误:

I am using htmlunit 2.36.0 in my Android Studio Project. I successfully compiled the apk but I am getting some runtime errors when I try to get a webpage. Before, I was getting the following error:

java.lang.BootstrapMethodError: Exception from call site

但是我能够通过在gradle中添加它来解决此问题:

But I was able to fix the issue by adding this in the gradle:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

但是,现在我面临另一个错误:

However, now I am facing another error:

 java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151)
        at com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory.buildSSLSocketFactory(HtmlUnitSSLConnectionSocketFactory.java:89)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:635)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClientBuilder(HttpWebConnection.java:558)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:519)
        at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:171)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1407)
        at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1326)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:396)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:469)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450)

显然,在其自己的类或父类中没有AllowAllHostnameVerifier的静态字段实例.我不知道该如何解决.

Apparently, there is no static field instance of AllowAllHostnameVerifier in its own class or or its superclasses. I have no idea how to fix this.

推荐答案

hc.apache.org 所述:

AllowAllHostnameVerifier已过时. (4.4)使用NoopHostnameVerifier

AllowAllHostnameVerifier Deprecated. (4.4) Use NoopHostnameVerifier

如果将依赖项的版本降级为4.3(2013〜2015),则将解决异常.

If you downgrade dependencies's version to 4.3(2013~2015) exception will be resolved.

implementation 'net.sourceforge.htmlunit:htmlunit:2.15'

这篇关于在Android Studio项目中使用htmlunit时,没有类型为Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier的静态字段INSTANCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆