rJava: pass 2 dimensional string array as function input

Viewed 855

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?

1 Answers
Related