I need to pass from Java
List< List<MyPoint> > points;
over jni to C++ and convert to
std::vector< std::vector<MyPoint> >
Process this vectors and return
List< List<MyPoint> >
As i understand it from the reference the JNI, JNI can only work with one-dimensional arrays of primitive types or objects.
Because on the side of Java, had to translate the list into an array. Then, in the native part the array passed and the number of elements. There's going to the desired vector and processed. Returns as a result of two arrays (array with points all contours and the array with the number of points in each contour) and the number of contours. The resulting array is collected in a list of lists on the side of Java.
While the problem is not solved completely, because the JNI can not allocate memory for an existing item in the native part. Therefore it is necessary to extract the data in part, to allocate memory for them on the side of Java, and fill in the native.
A possible resolve may be the use of binders such as SWIG or JavaCpp
JNIEXPORT jobjectArray JNICALL Java_ProcessInformation_getAllProcessPid (JNIEnv*env,jobject obj) {
vector<string>vec;
vec.push_back("Ranjan.B.M");
vec.push_back("Mithun.V");
vec.push_back("Preetham.S.N");
vec.push_back("Karthik.S.G");
cout<<vec[0];
cout<<vec[0];
jclass clazz = (env)->FindClass("java/lang/String");
jobjectArray objarray = (env)->NewObjectArray(vec.size() ,clazz ,0);
for(int i = 0; i < vec.size(); i++) {
string s = vec[i];
cout<<vec[i]<<endl;
jstring js = (env)->NewStringUTF(s.c_str());
(env)->SetObjectArrayElement(objarray , i , js);
}
return objarray;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With