I am trying to call the method from one class using a method within a second class (which should return a list), however, the second class method is not being recognised. I don't receive any visible errors or warnings.
My first class:
import java.util.*;
public class testClass {
public static List<Object> makeStuff() {
int a = 2;
double b = 3.1;
return Arrays.asList(a, b);
}
}
And the second
import java.util.*;
public class otherClass {
public List<Object> outputStuff() {
// create some other stuff here which will be appended to id
List<Object> id = testClass.makeStuff();
return id ;
}
public void main(String[] args) {
}
}
From How to access a method from a class from another class? I thought this would work as the first method is static. Where am I making the mistake please?
Extra info if required: I am actually interfacing this code with R using rJava
, but receive an error indicating that the java
is wrong.
This returns the values as expected for the first class/method
library(rJava)
.jinit()
.jaddClassPath("C:\\Users\\david\\eclipse-workspace\\SOtest\\bin")
myJavaClass <- .jnew("testClass")
x <- J(myJavaClass, "makeStuff")
x
# [1] "Java-Object{[2, 3.1]}"
but not for the second
.jinit()
.jaddClassPath("C:\\Users\\david\\eclipse-workspace\\SOtest\\bin")
myJavaClass <- .jnew("otherClass")
x <- J(myJavaClass, "outputStuff")
throws the error
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.lang.NoSuchMethodException: otherClass.outputStuff()