简体   繁体   English

DynamoDBMapper - 无法实例化类

[英]DynamoDBMapper - Failed to instantiate class

I'm running into an issue of the Java based DynamoDBMapper in Amazon's AWS toolkit throwing the "Failed to instantiate class" exception error.我在 Amazon 的 AWS 工具包中遇到了基于 Java 的 DynamoDBMapper 的问题,抛出“无法实例化类”异常错误。 This is my first time attempting to use the DBMapper, so I'm not entirely sure I have everything setup right.这是我第一次尝试使用 DBMapper,所以我不完全确定我的所有设置都正确。 My code can be found below:我的代码可以在下面找到:

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; }
}

I'm basically just trying to perform a GetItemRequest and then draw out a specific attribute, but I'm getting the error pointing to the line PStatus data = mapper.load(PStatus.class, "onFarm", new Integer(1655));我基本上只是尝试执行 GetItemRequest 然后绘制一个特定的属性,但我收到指向行的错误PStatus data = mapper.load(PStatus.class, "onFarm", new Integer(1655)); . . What exactly am I doing wrong?我到底做错了什么?

Edit: Exact Exception below:编辑:下面的确切异常:

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)

Add empty constructor so the call java.lang.Class.newInstance0(Unknown Source) will work:添加空构造函数,以便调用 java.lang.Class.newInstance0(Unknown Source) 将起作用:

public PStatus()
{

}

Just figured out the answer.刚刚想出答案。 It wasn't quite what I thought, but it ended up being that I had the class in the wrong location.这不是我想的那样,但最终我在错误的位置上课。 The way they showed it, I was under the impression that it was a sub-class, but PStatus needed to be its own class, file and all.他们展示它的方式,我的印象是它是一个子类,但 PStatus 需要是它自己的类、文件等等。 I was trying to sub-class it inside of TestGet and it wasn't liking that.我试图在 TestGet 内部对它进行子类化,但它不喜欢那样。 Guess it was more a Java issue I was having than the DBMapper.猜猜这更像是我遇到的 Java 问题而不是 DBMapper。 Still learning!还在学习!

我遇到了同样的问题,并通过删除正在初始化的类的所有构造函数来解决它。

It can also happen that you have used two DynamoDBVersionAttribute.您也可能使用了两个 DynamoDBVersionAttribute。 Its not happening in you use-case but for that also can get this error.它不会发生在您的用例中,但为此也会出现此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法实例化一个或多个类 - Failed to instantiate one or more class DynamoDB NoSQL并无法实例化类的新实例 - DynamoDB NoSQL and Failed to instantiate new instance of class 无法实例化UriInfo指定的类是接口 - Failed to instantiate UriInfo Specified class is an interface 如何解决“无法实例化 WebApplicationInitializer 类” - How to solve “Failed to instantiate WebApplicationInitializer class” 无法在以前工作的脚本上实例化类 - Failed to instantiate class on a previously working script 黄瓜.runtime.CucumberException:无法实例化类 - cucumber.runtime.CucumberException: Failed to instantiate class 如何解决“无法实例化WebApplicationInitializer类” - How to solve “Failed to instantiate WebApplicationInitializer class” Spring Boot WebFluxTest 测试,无法实例化存储库,指定类为接口 - Spring Boot WebFluxTest test, failed to instantiate repository, specified class is an interface Jboss 无法实例化类“org.jboss.logmanager.handlers.PeriodicRotatingFileHandle - Jboss Failed to instantiate class "org.jboss.logmanager.handlers.PeriodicRotatingFileHandle XML,Android Studio中的“无法实例化一个或多个类”错误 - “Failed to instantiate one or more class” error in XML, Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM