c++ - Return object from java native method -


i call method through native java interface, returns object.

this native method

public native node getprojectionpoint(double lat, double lon);   

node class

 public class node {             private string id;     private double latitude;     private double longitude; } 

c header file

jniexport jobject jnicall java_org_smartcar_serverdatainterface_shared_services_cppconnector_getprojectionpoint (jnienv *env, jobject obj, jdouble lat, jdouble lon); 

how create object , return java?

in jni have method

jnienv->newobject() invokes actual constructor of given java class.

maybe like:

jniexport jobject jnicall java_org_smartcar_serverdatainterface_shared_services_cppconnector_getprojectionpoint (jnienv *env, jobject obj, jdouble lat, jdouble lon) {   jclass cls = env->getobjectclass(obj);   jmethodid constructor = env->getmethodid(cls, "<init>", "(dd)v");   return env->newobject(cls, constructor, lat, lon); } 

you should modify class constructor receive 2 parameters. can initialize field field, requires invoke getfieldid 2 times in c++.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -