urielSilva
urielSilva

Reputation: 410

IValueFactory error trying to call Java method from Rascal

This question is similar to this one. I am trying to call a Java method from Rascal, but I'm getting an error (this time a different one):

Cannot link method com.mypackage.Teste because: com.mypackage.Teste.<init>(io.usethesource.vallang.IValueFactory).

Rascal code:

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

Java code:

package com.mypackage;

import io.usethesource.vallang.IValueFactory;

public class Teste {
    private final IValueFactory vf;

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

I noticed that I was using an old Rascal version (0.8), as pointed out in this comment. I changed it to 0.9 but the error remains. I'm using Eclipse Rascal plugin.

Upvotes: 1

Views: 123

Answers (1)

Anya
Anya

Reputation: 271

So, to summarise the discussion, likely causes of this error include:

  1. Your Java class needs a public constructor that takes an IValueFactory argument, as seen in the other question. E.g.,public ClassName(IValueFactory vf) { this.vf = vf; }
  2. You have added (1), and the Java class has been recompiled, but Rascal didn't reload it – in which case the solution is (for now) to close the Rascal console and re-open it. I'm not sure if Rascal intends to check for class file changes.
  3. You have (1) and Rascal does reload the class, but the class file hasn't been recompiled, which seems to have been the problem in this case.
  4. As jurgenv mentions, your Eclipse project also needs both the Rascal and Java natures, otherwise the Java builder doesn't run. This should be correctly set up from the start, as long as you created it using New → Rascal Project. For reference, the natures part of your Eclipse .project file should look like this:

    <natures>
      <nature>rascal_eclipse.rascal_nature</nature>
      <nature>org.eclipse.jdt.core.javanature</nature>
      <nature>org.eclipse.pde.PluginNature</nature>
      <nature>rascal_eclipse.term_nature</nature>
    </natures>
    

Upvotes: 4

Related Questions