java.lang.RuntimeException:无法启动activity 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)‘
AWS SQS连接问题
发布于 2020-07-04 08:32:36
我建议使用AWS Java SDK V2。它将允许您使用替代的HTTP运行时,并避免在Android上工作时与Apache客户端的一些混乱。
AWS Java SDK V2存储库中的GitHub Issue #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()
发布于 2019-11-04 07:18:21
它起作用了。
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();
https://stackoverflow.com/questions/58677190
复制