尝试使用API​​时出错. java.lang.NoSuchFieldError:INSTANCE [英] Error while trying to use an API. java.lang.NoSuchFieldError: INSTANCE

查看:110
本文介绍了尝试使用API​​时出错. java.lang.NoSuchFieldError:INSTANCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java程序连接到smartsheet api. 最初,我对站点证书有问题,可以通过将其添加到Java密钥库中来解决.现在,当我尝试运行代码时,出现以下错误.

I am trying to connect to the smartsheet api using a java program. Initially I had problems with the site certificate which was resolved by adding it to the java keystore. Now when I am trying to run my code, I get the following error.

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955)
    at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
    at com.smartsheet.api.internal.http.DefaultHttpClient.<init>(DefaultHttpClient.java:64)
    at com.smartsheet.api.SmartsheetBuilder.build(SmartsheetBuilder.java:203)
    at SmartsheetConnection.main(SmartsheetConnection.java:13)

这是我的代码(我遵循了他们的文档).

This is my code (I followed their documentation).

import com.smartsheet.api.*;
import com.smartsheet.api.models.*;
import com.smartsheet.api.models.enums.*;
import com.smartsheet.api.oauth.*;

public class SmartsheetConnection {
    public static void main(String[] args) throws SmartsheetException {
        // Set the access token.
        Token token = new Token();
        token.setAccessToken("foo");
        Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken(token.getAccessToken()).build();
    }
}

抛出错误的行是(第144行)

The line that is throwing error is (line 144)

@Deprecated
    public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
        = AllowAllHostnameVerifier.INSTANCE; 

但是我不确定该怎么做.我正在使用Maven来获取依赖关系.它与Apache HttpComponents的版本有关吗?

but I am not sure what to make of it. I am using maven to get the dependencies. Does it have something to do with the version of the Apache HttpComponents?

这是pom.xml

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.smartsheet</groupId>
            <artifactId>smartsheet-sdk-java</artifactId>
            <version>2.0.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-apache-client</artifactId>
            <version>1.9</version>
        </dependency>
    </dependencies>

推荐答案

有关此错误的其他文章似乎表明,该错误通常是由于httpcore jar版本冲突造成的.即在类路径上的httpcore的较旧版本.

Other posts about this error seem to suggest that it's typically caused by conflicting versions of httpcore jar. i.e., an older version of httpcore on the classpath.

有关更多信息,建议您查看以下帖子:

For more information, I'd suggest you checkout the following posts:

java.lang.NoSuchFieldError:INSTANCE

这篇关于尝试使用API​​时出错. java.lang.NoSuchFieldError:INSTANCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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