Search code examples
javajava-native-interfaceprimitive

how to receive the double array with a function call from JNI?


I have a Java method which takes a String as parameter and returns a double array. I am calling it using CallObjectMethod from native code. How do I receive that double array that the Java method is returning and how do I convert it to a normal(C/C++) double array.


Solution

  • JNI has a jdoubleArray type that's returned when you call this method. So something like this:

    jdoubleArray retVal;
    
    retVal = env->CallObjectMethod(...);
    jdouble *element = env->GetIntArrayElements(retVal, 0);
    

    And then you can directly use the members of element