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)'
AWS SQS连接问题
答案 0 :(得分:0)
它的工作。
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();
答案 1 :(得分:0)
我建议使用AWS Java SDK V2 。在Android上工作时,它将允许您使用备用HTTP运行时,并避免与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()