mercredi 11 septembre 2019

Instantiation Exception while invoking method with parameter

I am trying to invoke method with parameter in a class using reflection. While instantiating the class, I get error "Instantiation Exception".

public class get_reflection {
int b1=20;
String classname="org.la4j.linear.LeastSquaresSolver";
Class<?> c = Class.forName(classname);
 Object user = c.newInstance();
Method m = org.la4j.linear.LeastSquaresSolver.class.getMethod("get",Integer.class);
Object o= m.invoke(user,b1 ); 
}

LeastSquareSolver.java

public class LeastSquaresSolver extends AbstractSolver implements LinearSystemSolver {
public LeastSquaresSolver(Matrix a) {
        super(a);

        // we use QR for this
        MatrixDecompositor decompositor = a.withDecompositor(LinearAlgebra.RAW_QR);
        Matrix[] qrr = decompositor.decompose();

        // TODO: Do something with it.
        this.qr = qrr[0];
        this.r = qrr[1];
    }

    public void get(Integer b9)
    {
        System.out.println(b9);

    }

I expect to invoke the method get and print the value. Currently, I get compiler error at c.newInstance();





Aucun commentaire:

Enregistrer un commentaire