JNI callback to Java method question

G

ginjasvinja

Hi all,

in my code I used to call Java method which is void and nas no
arguments, from native code, like:

jEnv->CallVoidMethod( obj, jEnv->GetMethodID( jEnv->GetObjectClass( obj
), "envDepInfo", "()V" ) );

Now I want to call Java method which is also void, but takes some int
arguments. I can not just say

jEnv->CallVoidMethod( obj, jEnv->GetMethodID( jEnv->GetObjectClass( obj
), "envDepInfo", "(I)V" ) );

because I have more than one arguments, and also I do not have any idea
how to pass that arguments. Does anyone can help me with this?

Thanks!
 
G

Gordon Beaton

Now I want to call Java method which is also void, but takes some int
arguments. I can not just say

jEnv->CallVoidMethod( obj, jEnv->GetMethodID( jEnv->GetObjectClass( obj
), "envDepInfo", "(I)V" ) );

because I have more than one arguments, and also I do not have any idea
how to pass that arguments. Does anyone can help me with this?

The signature for a method that takes two int arguments and returns
void is "(II)V". If you're unsure, you can always use "javap -s
MyClass" to see the correct signatures.

To invoke the method, simply include the int arguments in your call to
CallVoidMethod(), i.e.:

jEnv->CallVoidMethod(obj, mid, x, y);

Note that it's rarely a good idea to nest calls to JNI functions as
you've done with GetObjectClass() and GetMethodID() inside
CallVoidMethod(). What do you think will happen if one of them fails
and returns NULL?

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top