本文介绍了AmazonSQSClientBuilder.defaultClient()java.lang.NoSuchFieldError:类型为Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier的无静态字段INSTANCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.msgqueue3/com.example.msgqueue3.MainActivity}:java.lang.NullPointerException:尝试调用接口方法'com.amazonaws.services.sqs.在空对象引用上的model.CreateQueueResult com.amazonaws.services.sqs.AmazonSQS.createQueue(com.amazonaws.services.sqs.model.CreateQueueRequest)'

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 SQS connection problem

推荐答案

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

I suggest to use the AWS Java SDK V2. It will allow you to use an alternate HTTP runtime, and avoid some of the mess with the Apache client, when working on Android.

GitHub版本#1180 V2回购解决了这个主题.

GitHub Issue #1180 in the AWS Java SDK V2 repo addresses this topic.

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

Specifically, in your module-level build.gradle, add dependencies:

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

现在,初始化SQS客户端:

Now, initialize the SQS client:

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

这篇关于AmazonSQSClientBuilder.defaultClient()java.lang.NoSuchFieldError:类型为Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier的无静态字段INSTANCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:52