Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks Timo for your help and link. For posterity, I'm adding a complete code set that would go through the process of generating a 2D primitive array consumable by Java, from an existing C 2D primitive array.</p> <pre><code>// Returns a 2D float array from C to Java jobjectArray ndk_test_getMy2DArray(JNIEnv* env, jobject thiz, jlong context) { // Cast my context reference MyContextRef contextRef = (MyContextRef) context; // Get the length for the first and second dimensions unsigned int length1D = MyContextGet1DLength(contextRef); unsigned int length2D = MyContextGet2DLength(contextRef); // Get the 2D float array we want to "Cast" float** primitive2DArray = MyContextGet2DArray(contextRef); // Get the float array class jclass floatArrayClass = (*env)-&gt;FindClass(env, "[F"); // Check if we properly got the float array class if (floatArrayClass == NULL) { // Ooops return NULL; } // Create the returnable 2D array jobjectArray myReturnable2DArray = (*env)-&gt;NewObjectArray(env, (jsize) length1D, floatArrayClass, NULL); // Go through the firs dimension and add the second dimension arrays for (unsigned int i = 0; i &lt; length1D; i++) { jfloatArray floatArray = (*env)-&gt;NewFloatArray(env, length2D); (*env)-&gt;SetFloatArrayRegion(env, floatArray, (jsize) 0, (jsize) length2D, (jfloat*) primitive2DArray[i]); (*env)-&gt;SetObjectArrayElement(env, myReturnable2DArray, (jsize) i, floatArray); (*env)-&gt;DeleteLocalRef(env, floatArray); } // Return a Java consumable 2D float array return myReturnable2DArray; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload