Spark 'generated.java', Line 37, Column 53: No applicable constructor/method found for zero actua...

最近在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 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(){}
}

你可能感兴趣的:(Spark 'generated.java', Line 37, Column 53: No applicable constructor/method found for zero actua...)