我正在使用 HtlmUnit,当查询网页时,我在线程“AWT-EventQueue-0”java.lang.NoSuchFieldError: INSTANCE”中遇到异常

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

我无法使用从 sourgeforce 安装的 htmlUnit 库读取网页内容。我需要帮助来解决问题,因为我尝试重新安装库,修改pom文件,但没有对结果进行任何修改。其他答案似乎指出了这样一个事实:这是组件版本不兼容的结果,但使用以前版本的 htmlunit 也不起作用。 这是例外:

Conectando pagina Seniat
0 [AWT-EventQueue-0] DEBUG org.htmlunit.WebClient  - Get page for window named '', using WebRequest[<url="http://contribuyente.seniat.gob.ve/BuscaRif/BuscaRif.jsp", GET, EncodingType[name=application/x-www-form-urlencoded], [], {Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7, Accept-Encoding=gzip, deflate, br}, null>]
0 [AWT-EventQueue-0] DEBUG org.htmlunit.WebClient  - Load response for GET http://contribuyente.seniat.gob.ve/BuscaRif/BuscaRif.jsp
16 [AWT-EventQueue-0] DEBUG org.htmlunit.WebWindowImpl  - destroyChildren
**Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>**(SSLConnectionSocketFactory.java:151)
    at org.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:671)
    at org.htmlunit.HttpWebConnection.createHttpClientBuilder(HttpWebConnection.java:589)
    at org.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:545)
    at org.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:172)
    at org.htmlunit.WebClient.getWebResponseOrUseCached(WebClient.java:1654)
    at org.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1559)
    at org.htmlunit.WebClient.loadWebResponse(WebClient.java:1484)
    at org.htmlunit.WebClient.getPage(WebClient.java:451)
    at org.htmlunit.WebClient.getPage(WebClient.java:366)
    at org.htmlunit.WebClient.getPage(WebClient.java:504)
    at org.htmlunit.WebClient.getPage(WebClient.java:486)
    at com.openbravo.pos.smart.ConsultarSENIAT.consultarSENIAT(ConsultarSENIAT.java:73)
    at com.openbravo.pos.customers.CustomersView.jTextArea1MouseClicked(CustomersView.java:2186)
    at com.openbravo.pos.customers.CustomersView.access$900(CustomersView.java:69)
    at com.openbravo.pos.customers.CustomersView$8.mouseClicked(CustomersView.java:1305)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
...

代码

package com.openbravo.pos.smart;
import java.awt.image.BufferedImage;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.htmlunit.WebClient;
import org.htmlunit.html.HtmlPage;


/**
 *
 * @author Smart Office Factory
 */

public class ConsultarSENIAT {
public  Element CI;
public  Element RIF;
public  BufferedImage Captcha;
public  Element Boton;
public  Element Codigo;
public Document doc;

public ConsultarSENIAT(){   
    this.CI=CI;
    this.RIF=RIF;
    this.Captcha=Captcha;
    this.Boton=Boton;
    this.Codigo=Codigo;
}

    public String consultarSENIAT() {
        
       
        System.out.println("Conectando pagina Seniat");
        String Resultado="";
        
        try (final WebClient webClient = new WebClient()) {
            webClient.getOptions().setJavaScriptEnabled(true); // Habilitar JavaScript si es necesario
            webClient.getOptions().setCssEnabled(true); // Habilitar CSS si es necesario

            HtmlPage page = webClient.getPage("http://contribuyente.seniat.gob.ve/BuscaRif/BuscaRif.jsp");
            
            webClient.waitForBackgroundJavaScript(10000); // Esperar a que se cargue el JavaScript en segundo plano
            webClient.waitForBackgroundJavaScriptStartingBefore(10000); // Esperar a que comience la carga del JavaScript en segundo plano*/

            // Aquí puedes realizar acciones adicionales una vez que la página ha cargado completamente
            System.out.println("Título de la página: " + page.getTitleText());
            // Agrega tu código adicional aquí

        } catch (Exception e) {
            e.printStackTrace();
        }
        

使用 netbeans 8.2/JDK 1.8/HTLMUnit 4.0.0 和 POM.xlm:


<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>UnicentaSmarT</groupId>
  <artifactId>UnicentaSmarT</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>
  <dependencies>
    <dependency>
      <groupId>net.sourceforge.htmlunit</groupId>
      <artifactId>htmlunit</artifactId>
      <version>4.0.0</version>
    </dependency>
    <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.17.2</version>
</dependency>
  </dependencies>
</project>

我该如何解决这个错误。!谢谢

java exception instance pom.xml netbeans-8.2
1个回答
0
投票

你不知何故拿起了另一个版本的

HttpComponents
。我不认为你的 POM 是完整的,因为它没有显示你对 jsoup 的依赖,所以我无法猜测为什么你有多个版本的
HttpComponents
。查看依赖关系树,了解每个库的版本以及使用原因。运行
mvn dependency:tree
;要过滤结果,请参阅此示例。您需要依赖插件来生成依赖树。

在网络上搜索“SSLConnectionSocketFactory nosuchfielderror实例”可能会提供一些解决方案,尽管发生此异常时的原因通常是相同的:获取意外版本的

HttpComponents

我不认为这与您的问题有关,但值得引起您的注意。你说你使用的是 Java 8,但你的 POM 却有不同的说法:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

最后,NetBeans 已达到版本 21,因此可能需要进行更新。 :)

© www.soinside.com 2019 - 2024. All rights reserved.