繁体   English   中英

AmazonSQSClientBuilder.defaultClient() java.lang.NoSuchFieldError: No static Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier 类型的字段实例

[英]AmazonSQSClientBuilder.defaultClient() java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.msgqueue3/com.example.msgqueue3.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'com.amazonaws.services.sqs.model.CreateQueueResult com.amazonaws.services.sqs.AmazonSQS.createQueue(com.amazonaws.services.sqs.model.CreateQueueRequest)' on a null object reference

AWS SQS 连接问题

我建议使用 AWS Java SDK V2 在 Android 上工作时,它将允许您使用备用 HTTP 运行时,并避免 Apache 客户端的一些混乱。

AWS Java SDK V2 存储库中的GitHub 问题 #1180解决了此主题。

具体来说,在您的模块级build.gradle中,添加依赖项:

dependencies {
    implementation 'software.amazon.awssdk:sqs:2.13.49'
    implementation 'software.amazon.awssdk:url-connection-client:2.13.49'
}

现在,初始化 SQS 客户端:

val sqs = SqsClient.builder()
    .httpClient(UrlConnectionHttpClient.create())
    .region(Region.US_EAST_1)
    .credentialsProvider(yourCredentialsHere())
    .build()

它的工作。

     ProfileCredentialsProvider credentialsProvider = new ProfileCredentialsProvider();

    try {

        credentialsProvider.getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException(
                "Cannot load the credentials from the credential profiles file. " +
                        "Please make sure that your credentials file is at the correct " +
                        "location (~/.aws/credentials), and is in valid format.",
                e);

    }
    AmazonSQS sqs = AmazonSQSClientBuilder.standard()
            .withCredentials(credentialsProvider)
            .withRegion(Regions.US_WEST_2)
            .build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM