最近在Spark学习过程中,遇到了如下的错误:
java.util.concurrent.ExecutionException: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 37, Column 53: failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 37, Column 53: No applicable constructor/method found for zero actual parameters; candidates are: "LambdaStudy.Person(java.lang.String, java.lang.String, int)"
主要代码部分如下:
@Getter
@Setter
@AllArgsConstructor
public class Person implements Serializable {
private String firstName;
private String lastName;
private int age;
}
@Test
public void dataSetSingleTest() {
Person person = new Person("four", "li", 32);
Dataset<Person> dataset = ss.createDataset(
Collections.singletonList(person),
Encoders.bean(Person.class)
);
dataset.collectAsList();
}
查了许多资料都没有很好的解释。参考错误的提示,我尝试在Person类中添加了一个无参数的构造函数,问题解决。(但根本原因目前还不知道==!)修改代码如下:
@Getter
@Setter
@AllArgsConstructor
public class Person implements Serializable {
private String firstName;
private String lastName;
private int age;
public Person(){}
}
网友评论