how to call methods defined in another class ? is it possible?

Hi all,

I am new to using JNI, was wondering if this is possible and how I might be able to do this. I'm trying to call some set/get functions defined in a class that is not part of the class where I have my native code defined and called...

Let me explain a bit, I have a class JobElement (singular Job) that stores all the data associated with a Job, such as job name, job id, etc.

Another class JobsElement (plural Jobs) contains all the Jobs that are currently running.

The code is set up something like this...

class JobElement{

String jobID;

String jobName;

publicvoid setJobId(String newJobID){ jobID = newJobID;}

publicvoid setJobName(String newJobName){ jobName = newJobName;}

...

}

class JobsElement{

Date timeDateStamp;

JobElement job;

}

class AppRoot{

JobsElement allJobs =null;

JobElement _currentJob =null;

publicnative getAllJobs();

...

}

In my native method, getAllJobs(), I essentially want to call the set functions that are defined for JobElement when filling in the information of the Job. (then finally add the JobElement to the JobsElement list)

In summary, I basically want to know if it's possible to call the equivilent of this java code from the native code?

_currentJob.setJobName(newJob)

In the native code I tried to find the setJobID method but got a NoSuchMethodError. (which is what I expected)

Thanks in advance.

[2161 byte] By [victor.k.hua] at [2007-10-3 2:14:09]
# 1
And where are you going to get an instance of JobElement from in your JNI code?
jschella at 2007-7-14 19:12:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Not sure, In my AppRoot, I have defined _currentJob. Can I reference this from the JNI code? What I want to do is after I run the native getAllJobs() function, I would like _currentJob.jobId and _currentJob.jobName to have values filled in.
victor.k.hua at 2007-7-14 19:12:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
> Not sure, In my AppRoot, I have defined _currentJob.> Can I reference this from the JNI code? To call a non-static method you must have an instance. That just as true in JNI as it is in java.You need that first.
jschella at 2007-7-14 19:12:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

Hi,

In your getAllJobs(), the JNI Equiv would be JNIEnv_ClassName_getAllJobs(JNIEnv** anEnv, jobject jAppRootobj)

Since you are calling the AppRoot object's method, the jobj in the native method call will be jAppRootobj-AppRoot's instance.

What you can do is

Get the field id of _currentJob.

Get the <jobject-value of _currentJob> of JobElement i.e. _currentJob.

Then get the method ids of setJobID and setJobName.

Call these non-static methods on <jobject-value of _currentJob> to set the values.

I hope I made a try to help you. Please correct me if I am wrong.

DhamoJNIa at 2007-7-14 19:12:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...