带有Amazon AWS NoSuchFieldError的java

时间:2016-05-11 13:58:55

标签: java windows amazon-s3

带有Amazon AWS NoSuchFieldError的java

这是控制台日志:

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)

底线是我的代码交给亚马逊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。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

问题排序 - 库不匹配。

&#39; AWS-java的SDK-1.10.77.jar&#39;需要&#39; org.apache.httpcomponents.httpcore_4.4.4.jar&#39;在构建路径上。