2016-05-11 204 views
1

用java亞馬遜AWS NoSuchFieldError用java亞馬遜AWS NoSuchFieldError

這裏是控制檯日誌:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: INSTANCE 

at org.apache.http.client.utils.URLEncodedUtils.parse(URLEncodedUtils.java:246) 
at org.apache.http.client.utils.URLEncodedUtils.parse(URLEncodedUtils.java:225) 
at org.apache.http.client.utils.URIBuilder.parseQuery(URIBuilder.java:95) 
at org.apache.http.client.utils.URIBuilder.digestURI(URIBuilder.java:165) 
at org.apache.http.client.utils.URIBuilder.<init>(URIBuilder.java:90) 
at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:138) 
at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:353) 
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:476) 
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) 
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:837) 
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:607) 
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:376) 
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:338) 
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:287) 
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3826) 
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3778) 
at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:610) 
at net.pocketsurvey.cloud.Amazon.listObjectsInBucket(Amazon.java:93) 

底線是我的代碼移交到Amazon的S3。代碼如下:

public static ObjectListing listObjectsInBucket(String bucketName, 
    String key) throws Exception { 
    ObjectListing list = null; 
    AmazonS3Client client = Client.s3(Client.DESKTOP); 
    try { 
    boolean b_exists = client.doesBucketExist(bucketName); 
    boolean o_exists = client.doesObjectExist(bucketName, key); 
    if(b_exists) { 
     list = client.listObjects(bucketName, key); 
    } 
    } catch (AmazonServiceException e){ 
    String err = e.getErrorMessage(); 
    e.printStackTrace(); 
    } catch (AmazonClientException e){ 
    e.printStackTrace(); 
    } catch (Exception e){ 
    e.printStackTrace(); 
    } 
    return list; 
    } 

'client.listObjects'是炸彈出來的地方。使用

庫包括: AWS-java的SDK-1.10.77.jar HttpClient的-OSGi的4.3.jar org.apache.httpcomponents.httpcore_4.2.1.jar

'b_exists' 是事實,但即使是絕對存在的關鍵字,'o_exists'也會返回false。

我使用的憑據可用於其他事情,例如電子郵件,並下載已知對象,即完整的密鑰字符串。但試圖使用部分密鑰字符串(如「hhs /」)獲取列表,我得到了上面的錯誤。

此外,'捕捉'不抓住它。

該代碼當前在UI線程上運行,但我已經在其自己的線程上嘗試過,結果類似。

該平臺是Windows 7.

任何幫助將不勝感激。

回答

0

問題排序 - 庫不匹配。

'aws-java-sdk-1.10.77.jar'needs'org.apache.httpcomponents.httpcore_4.4.4.jar'to bein the build path。

+0

我們如何從文檔中瞭解這一點? @Mike利馬 –