Spark报错问题记录

  1. Caused by: org.codehaus.commons.compiler.CompileException ...No applicable constructor/method found for zero actual parameters;

Caused by: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 108, Column 25: failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 108, Column 25: No applicable constructor/method found for zero actual parameters; candidates are: "public java.lang.String xxx.xxx.UserBehavior.getTimestamp()"

原因是Spark需要public的JavaBean类。而java中一个文件中只能有一个public修饰的类,解决方案就是单独放到一个类,或者在同一个文件中定义为静态的public内部类

Dataset<Row> userBehaviorData = spark.createDataset(
  Arrays.asList(
    new UserBehavior("user123", "view", "product001", "cat001", "region_A", "2024-01-01 10:00:00")
  ),
  Encoders.bean(UserBehavior.class)
).toDF();
posted @ 2025-10-22 22:25  vonlinee  阅读(4)  评论(0)    收藏  举报