سؤال

I am facing an issue with returning any type of array with .jcall(). Here is my code.

public class Test(){
  public static double[] sample(){

  double[] nobjarr = new double[5]
  nobjarr[0] = 1.0;
  nobjarr[1] = 1.0;
  nobjarr[2] = 1.0;
  nobjarr[3] = 1.0;
  nobjarr[4] = 1.0;

  return nobjarr;
}

}

In R, I am calling using .jcall

library(rJava)                          
.jinit()   
.jaddClassPath("path to .class file")    
objT <- .jnew("Test")    
res  <- .jcall(objT,"[D","sample")

For this I get an error saying "Error in .jcall(objT, "[D", "sample") :method sample with signature ()[D not found"

هل كانت مفيدة؟

المحلول

Have you tried something like this:

Test <- J( "Test" )
Test$sample()

This uses the reflection based API that is in rJava for several years now and is much more convenient than the low level .jnew, .jcall interface.

نصائح أخرى

I don't know rJava, but it looks like you were telling the library to look for an instance method when the method is actually static. Check the documentation to see what the first argument to jcall should be for a static method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top