No applicable constructor/method found for actual parameters "int" but the matching candidate does exist

2.1k Views Asked by At

I want to add some code inside the Spark-SQL generated java code. So I create a jar file that has a class "Employee" and manually insert 'Employee e = new Employee(some integer)' in the file: sql/core/src/main/scala/org/apache/spark/sql/execution/WholeStageCodegenExec.scala. When invoking spark-shell, I did 'spark-shell --jars /path/to/myJar.jar'. However, when I run the query, it reports this error: ERROR CodeGenerator: failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 21, Column 18: No applicable constructor/method found for actual parameters "int"; candidates are: "Employee()", "Employee(int)", "Employee(java.lang.String)"

Most similar questions I found online are because the parameter type mismatch, however, I do have Employee(int) constructor as you can see here, why Janino still complained about it??

My Employee example is pretty simple:

public class Employee {
  String name = "Default";
  int age;
  int ID;

  Employee() {
    System.out.println("Empty constructor");
  }

  Employee(String myName) {
    name = myName;
  }

  Employee(int myAge) {
    age = myAge;
  }

  void sayHi() {
    System.out.println("Hello, I'm " + name);
  }

  void sayhello() {
    System.out.println("Hello,test");
  }
}

And the modified generated code is also simple as:

public void init(int index, scala.collection.Iterator[] inputs) {
  String name = "Go";
  int age = 30;
  Employee e1 = new Employee(age);
  e1.sayHi();

Really appreciate your help!!!

1

There are 1 best solutions below

1
On BEST ANSWER

I'm not familiar with the Spark codegen, but it's one issue with the Java code.

All constructors of the Employee class are decrared with the default access, so they are not accessible from the other packages. Try to declare constructor with public modifier.