java.lang.IllegalArgumentException:找不到声明的字段类 org.apache.http.impl.client.HttpClientBuilder.dnsResolver

问题描述 投票:0回答:1

参考:

https://devpal.co/blog/web-scraping-with-java-and-htmlunit/

我正在执行与博客中提到的完全相同的步骤,但出现错误

java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver

下面的电话

HtmlPage myPage = webClient.getPage("https://devpal.co");

pom.xml 条目

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.70.0</version>
</dependency>
java htmlunit
1个回答
0
投票

出于某种原因,您的类路径中有不同版本的 Apache Httpclient。

我觉得可能有两个原因:

  • 项目中的另一个库需要旧版本,因此 maven 选择这个库
  • 您使用的是 android(android jre 中内置了一个旧版本)。如果您使用的是 Android,请改用 HtmlUnit Android 包(https://github.com/HtmlUnit/htmlunit-android
© www.soinside.com 2019 - 2024. All rights reserved.