rJava .jcall return type issue

你离开我真会死。 提交于 2019-12-11 16:07:52

问题


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"


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/18656732/rjava-jcall-return-type-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!