gpt4 book ai didi

java - DynamoDBMapper - 无法实例化类

转载 作者:搜寻专家 更新时间:2023-10-31 08:15:15 27 4
gpt4 key购买 nike

我在 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",新整数(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()
{

}

关于java - DynamoDBMapper - 无法实例化类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16246526/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com