urielSilva
urielSilva

Reputation: 410

Error trying to call Java method from Rascal

I am trying to call a Java method from Rascal, but I'm getting this error:

Cannot link method com.mypackage.Teste because: class not found

Rascal code:

@javaClass{com.mypackage.Teste}
java void testeJava();

Java code:

package com.mypackage;

public class Teste {
    public void testeJava() {
        System.out.println("it worked");
    }
}

The com.mypackage package is inside my src folder, along with all of the Rascal code. I've also tried to use src.com.mypackage.Teste as well, but had the same result.

What am I doing wrong?

Upvotes: 1

Views: 199

Answers (1)

Davy Landman
Davy Landman

Reputation: 15439

The class needs one constructor that has one argument of the IValueFactory type. You will often store this in a field, as it is the way to respond to the function call. (Build IValues with this factory)

package com.mypackage;

import io.usethesource.vallang.IValueFactory;

public class Teste {
    private final IValueFactory vf;

    public Tests(IValueFactor vf) {
       this.vf = vf;
    }
    public void testeJava() {
        System.out.println("it worked");
    }
}

Upvotes: 1

Related Questions