Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

retrieving objects form JNI

Thread view: 
Edsoncv - 15 Aug 2006 16:40 GMT
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
Gordon Beaton - 15 Aug 2006 17:27 GMT
> 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).
[quoted text clipped - 6 lines]
>   (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

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Edsoncv - 17 Aug 2006 15:22 GMT
Perfect, It works. Thanks a lot!!!

> > 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).
[quoted text clipped - 31 lines]
> [ don't email me support questions or followups ]
> g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.