Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rJava - .jcall calling issue: method with signature not found

Tags:

r

rjava

I am trying to call a method in java class with rJava for a few days and I did not yet figure it out what I am doing wrong. Maybe someone here will have a some clues for me.

The situation looks like this:

  1. I load library and initializing an object (that's works fine):

    library(rJava)
    .jinit('C:/javatemp/worker.jar') 
    jobject <- .jnew("worker.concrete")
    
  2. I list methods and I get fine result:

    .jmethods(jobject)
    >  [1] "public java.util.List worker.concrete.lookup(java.lang.CharSequence)"  
    
  3. I am preparing input structure which also works fine:

    word <- .jnew("java/lang/String", "a word")
    input = .jcast(word, "java/lang/CharSequence", check = TRUE)
    
  4. However when I am trying to execute the method I get an error that such method does not exist...

    out = .jcall(jobject,"Ljava/util/List","lookup",input)
    > Error in .jcall(jobject, "Ljava/util/List", "lookup", input) : 
    method lookup with signature (Ljava/lang/CharSequence;)Ljava/util/List not found
    

Does anyone have an idea how to call such method?

like image 772
eye Avatar asked Mar 15 '15 21:03

eye


1 Answers

Sorry for answering an old question, but this has bugged me as well for some time. The answer is: ;

The format of type specification for non-primitive return types is Lpackage/subpackage/Type; - it has to end with a semicolon. So in the example above, you would need:

out = .jcall(jobject,"Ljava/util/List;","lookup",input)
like image 189
Martin Modrák Avatar answered Sep 23 '22 04:09

Martin Modrák