DynamoDBMapper-无法实例化类

来源:爱站网时间:2021-09-27编辑:网友分享
我在Amazon的AWS工具包中遇到了一个基于Java的DynamoDBMapper的问题,引发了“无法实例化类”异常错误。这是我第一次尝试使用DBMapper,所以...

问题描述


我在Amazon的AWS工具包中遇到了一个基于Java的DynamoDBMapper的问题,引发了“无法实例化类”异常错误。这是我第一次尝试使用DBMapper,所以我不确定我是否正确设置了所有设置。我的代码可以在下面找到:

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)

解决方法:


添加空构造函数,因此调用java.lang.Class.newInstance0(Unknown Source)将起作用:

public PStatus()
{

}

上一篇:如何检查字符串是否仅包含ASCII?

下一篇:Android应用没有互联网连接-无需权限

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载