簡體   English   中英

AmazonSQSClientBuilder.defaultClient() java.lang.NoSuchFieldError: No static Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier 類型的字段實例

[英]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

AWS SQS 連接問題

我建議使用 AWS Java SDK V2 在 Android 上工作時,它將允許您使用備用 HTTP 運行時,並避免 Apache 客戶端的一些混亂。

AWS Java SDK V2 存儲庫中的GitHub 問題 #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()

它的工作。

     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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM