3

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

Sajeenthiran
  • 417
  • 5
  • 11
  • [What is NullPointerException and how to fix it?] (https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it/218510#218510) – Giddy Naya Nov 03 '19 at 04:38
  • thank you. AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); not working for me – Sajeenthiran Nov 03 '19 at 05:30

2 Answers2

0

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 Issue #1180 in the AWS Java SDK V2 repo addresses this topic.

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'
}

Now, initialize the SQS client:

val sqs = SqsClient.builder()
    .httpClient(UrlConnectionHttpClient.create())
    .region(Region.US_EAST_1)
    .credentialsProvider(yourCredentialsHere())
    .build()
Jameson
  • 6,400
  • 6
  • 32
  • 53
-1

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();
Sajeenthiran
  • 417
  • 5
  • 11