File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes call jni method from another method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "call jni method from another method" Watch "call jni method from another method" New topic
Author

call jni method from another method

bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi,

i want to know if we can call a jni method in another method, because it never worked for us.

so let me explain in detail.


i have a method (function)called in c++ file named, let us say phone.cpp

void answer()

we have written a jni for that method and modified the void answer to

JNIEXPORT void JNICALL Java_testall_answer(JNIEnv *env, jobject jobj)

now we wanted to call the void answer() method in another function of the c++ file (phone.cpp).

how can it be made.

we tried

answer();
Java_testall_answer();
Java_testall_answer(JNIEnv *env, jobject jobj);
JNICALL Java_testall_answer(JNIEnv *env, jobject jobj);
JNICALL Java_testall_answer();

nothing worked..

kindly help.


thanks in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

bharani rao wrote:Java_testall_answer(JNIEnv *env, jobject jobj);

What happens if you remove the types:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164

hi rob,

it did not work..

i doubt if it is possible..

thank you in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Can you show me the method that is trying to call the native method?
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi rob,

this is the api that is calling that jni method

static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,pjsip_rx_data *rdata)


this is from pjsip stack



thank you
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Then it seems that you have no access to JNIEnv* and jobject variables to pass to that method. You need to have a reference to those somehow.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
thank you rob....

i will try and inform you the status.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi rob,

we tried hard and managed to proceed with our project without calling the jni method n another method..
we recreated the things done in the other method in the jni method and an additional method



thank you.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

bharani rao wrote:hi rob,

we tried hard and managed to proceed with our project without calling the jni method n another method..
we recreated the things done in the other method in the jni method and an additional method


It strikes me that this is the better implementation anyway. Write a non-JNI version of your code, then implement the JNI method to call the non-JNI one to get the work done. That way there's no code duplication, and the non-JNI method can be easily called from wherever.


[Jess in Action][AskingGoodQuestions]
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi ernest,

you are right...
it worked for us... it is easy if we do so with out any complications like the other procedure



thank you
 
Consider Paul's rocket mass heater.
 
subject: call jni method from another method