[英]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 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 connection problem AWS SQS 连接问题
I suggest to use the AWS Java SDK V2 .我建议使用 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.在 Android 上工作时,它将允许您使用备用 HTTP 运行时,并避免 Apache 客户端的一些混乱。
GitHub Issue #1180 in the AWS Java SDK V2 repo addresses this topic. AWS Java SDK V2 存储库中的GitHub 问题 #1180解决了此主题。
Specifically, in your module-level build.gradle
, add dependencies:具体来说,在您的模块级build.gradle
中,添加依赖项:
dependencies {
implementation 'software.amazon.awssdk:sqs:2.13.49'
implementation 'software.amazon.awssdk:url-connection-client:2.13.49'
}
Now, initialize the SQS client:现在,初始化 SQS 客户端:
val sqs = SqsClient.builder()
.httpClient(UrlConnectionHttpClient.create())
.region(Region.US_EAST_1)
.credentialsProvider(yourCredentialsHere())
.build()
its working.它的工作。
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.