retrieving objects form JNI

E

Edsoncv

Hello
I have the following problem. In Java I have a class named nlo, it has
as its members three objects of type nla (say nla1, nla2, nla3). The
class nla has a method setx(). I would like to access the method
nla.setx() from C++ using JNI. The arguments of my native function is
something like this (generated by Javah):

JNIEXPORT void JNICALL
Java_br_com_vrtech_JEqs_JNLPSolver_solveNLPnative
(JNIEnv * env,
jobject obj_this)

I have done the code bellow but I can go on since I don't know how to
access a method of an object that is a member of another.

jclass cls
jmethodID mid;
jfield fnlp1;

refe = env->PushLocalFrame(20);

cls = env->GetObjectClass(obj_this));

fnlp1 = env->GetFieldId(cls, "nlp", "methodsignature");

How to get a reference to nla1 or nla2, or nla3. I hope I made myself
clear.

Thanks
 
G

Gordon Beaton

I have the following problem. In Java I have a class named nlo, it
has as its members three objects of type nla (say nla1, nla2, nla3).
The class nla has a method setx(). I would like to access the method
nla.setx() from C++ using JNI. The arguments of my native function
is something like this (generated by Javah):

JNIEXPORT void JNICALL
Java_br_com_vrtech_JEqs_JNLPSolver_solveNLPnative
(JNIEnv * env,
jobject obj_this)

This method does not appear to belong to an object of type nlo...

I have done the code bellow but I can go on since I don't know how
to access a method of an object that is a member of another.

1. Use FindClass() or GetObjectClass() to get the nlo class.

2. Get the 3 fieldIDs from the nlo class with GetFieldID().

3. Use GetObjectField() to get the 3 object references from an nlo
object.

4. Get the nla class with GetObjectClass() and one of the 3 objects,
or use FindClass().

5. Get the setx() methodID from the nla class with GetMethodID().

6. Invoke setx() on each of the 3 objects, with CallVoidMethod().


/gordon
 
E

Edsoncv

Perfect, It works. Thanks a lot!!!


Gordon said:
This method does not appear to belong to an object of type nlo...



1. Use FindClass() or GetObjectClass() to get the nlo class.

2. Get the 3 fieldIDs from the nlo class with GetFieldID().

3. Use GetObjectField() to get the 3 object references from an nlo
object.

4. Get the nla class with GetObjectClass() and one of the 3 objects,
or use FindClass().

5. Get the setx() methodID from the nla class with GetMethodID().

6. Invoke setx() on each of the 3 objects, with CallVoidMethod().


/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

Similar Threads


Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top