In my java class I write 3 test functions as follows:
public void try2dStringArray(String[][] arr) {
System.out.println(arr.length);
}
public void try1dStringArray(String[] arr) {
System.out.println(arr.length);
}
public void try2dDoubleArray(double[][] arr) {
System.out.println(arr.length);
}
In R part I run the following:
library(rJava)
.jinit('/path/to/my/jar/app.jar')
obj <- .jnew('somepackage.Someclass')
doubleMatrix <- rbind(c(1,2), c(3,4))
stringMatrix <- rbind(c('a', 'b'), c('c', 'd'))
stringArray <- c('a', 'b')
result <- .jcall(obj,"V","try1dStringArray",
.jarray(stringArray, dispatch = T))
result <- .jcall(obj,"V","try2dDoubleArray",
.jarray(doubleMatrix, dispatch = T))
result <- .jcall(obj,"V","try2dStringArray",
.jarray(stringMatrix, dispatch = T))
Only the last one errors out:
Error in .jcall(obj, "V", "try2dStringArray", .jarray(stringMatrix, dispatch = T)) :
method try2dStringArray with signature ([[Ljava.lang.String;)V not found
How is String[][] different from double[][] in this case and how can I fix it?
.jarray(lapply(apply(stringMatrix,1,function(x) lapply(x,.jnew,class="java/lang/String")),.jarray))create aString[][]java object suitable for your method?Error in .jcall(obj, "V", "try2dStringArray", .jarray(lapply(apply(stringMatrix, : method try2dStringArray with signature ([Ljava/lang/Object;)V not foundObject[][]instead ofString[][]. I looked at the doc of.jarrayand maybe using the argumentcontents.classwill solve:.jarray(apply(stringMatrix,1,.jarray),contents.class="java/lang/String"). I also simplified a little the command. Hope this works.Error in .jcall(obj, "V", "try2dStringArray", .jarray(apply(stringMatrix, : method try2dStringArray with signature ([Ljava/lang/String;)V not foundobj$try2dStringArray(.jarray(stringMatrix, dispatch = T))it should work (at least, it works for me, printing2). Maybe it's a bug in.jcall.