我遇到了亞馬遜AWS工具包中基於Java的DynamoDBMapper的問題,該問題拋出「無法實例化類」異常錯誤。這是我第一次嘗試使用DBMapper,所以我不完全確定我有一切設置正確。我的代碼可以發現如下:DynamoDBMapper - 無法實例化類
public static void main(String[] args) {
dynamoDB = new AmazonDynamoDBClient(credentials);
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDB);
PStatus data = mapper.load(PStatus.class, "online", new Integer(1655));
String assigned = data.getAssigned();
System.out.println(assigned);
}
@DynamoDBTable(tableName = "projectStatus")
public class PStatus {
private Integer projID;
private String status;
private String assigned;
@DynamoDBHashKey(attributeName = "status")
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
@DynamoDBRangeKey(attributeName = "projID")
public Integer getId() { return projID; }
public void setId(Integer projID) { this.projID = projID; }
@DynamoDBAttribute(attributeName = "assigned")
public String getAssigned() { return assigned; }
public void setAssigned(String assigned) { this.assigned = assigned; }
}
基本上,我只是想執行一個GetItemRequest然後繪製出一個特定的屬性,但我越來越指着線PStatus data = mapper.load(PStatus.class, "onFarm", new Integer(1655));
錯誤。我究竟做錯了什麼?
編輯:下面精確異常:
Exception in thread "main" com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: Failed to instantiate class
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.createKeyObject(DynamoDBMapper.java:325)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.load(DynamoDBMapper.java:313)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.load(DynamoDBMapper.java:212)
at test.TestGet.main(TestGet.java:20)
Caused by: java.lang.InstantiationException: test.TestGet$PStatus
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.createKeyObject(DynamoDBMapper.java:323)
能否請您編輯和添加完整的異常堆棧?最初是一個InstantiationException或IllegalAccessException?你可以創建一個新的PStatus實例嗎? – 2013-04-28 10:16:26
用確切的例外進行了更新。第20行是我之前提到的。他們並沒有詳細討論如何使用映射器獲取數據,只是指出使用load方法是可能的。他們給load方法的例子只包括我得到錯誤的那一行(而不是其餘部分);唯一的區別是類名(我已經嘗試了他們使用的名稱;沒有骰子)。我可能只是想出了一些可以嘗試的東西;我會告訴你,如果我的想法是正確的,或者一旦我嘗試它... – DGolberg 2013-04-29 00:48:14