I have to return a array of structure values from c++ (jni) to java. I have the c++ struture as follows
MyCStructure
{
byte *Data;
int dataLength;
int width;
int height;
}mycstr;
And i have my java structure as
public class MyJavaStructure
{
public byte[] Data;
public int dataLength;
public int width;
public int height;
}
And My JavaMainClass.java is
MyJavaStructure[] mystr = MyJavaStructure[4];
public native int Process();
public LSImage getValues()
{
return this.mystr ;
}
public void setValues(MyJavaStructure bDetails)
{
this.mystr = bDetails;
}
I tried to pass Object array (MyJavaStructure) directly from JNI using GetMethodId of setValues.
My JNI code is
JNIEXPORT jint JNICALL Java_TestJNI_Process(JNIEnv *jEnv, jobject jObj)
{
MyCStructure* mycstr = new MyCStructure[4];
iRet = Process(&mycstr);
jclass jClass = jEnv->GetObjectClass(jObj);
jmethodID constructor;
jmethodID jObjectID = jEnv->GetMethodID (jLegendClass, "setValues", "(LMyCStructure;)V");
if (jObjectID == NULL)
{
throwJavaException(jEnv, "Unable to find the method setValues");
return NULL;
}
jEnv->CallObjectMethod(jObj, jObjectID, (jobject *) mycstr);
printf ("After setting the output data value\n");
jEnv->DeleteLocalRef(jClass);
return iRet;
}
The value returned in mycstr contains 4 array of structure (MyCStructure) values and i tried to assign in a MyJavaStructure class object but it returned null.
Am i doing right or is there i have to change anything ?