For Programmers: Free Programming Magazines  


Home > Archive > Java Help > February 2006 > JNI: Multi-dimensional (3-D) Array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author JNI: Multi-dimensional (3-D) Array
Andreas

2006-02-22, 7:01 pm

Hi,

Am having trouble with passing multi-dimensional arrays from C++ to Java.

The Java method receives an object but it's contents are null.
The received (in Java) object's length is correct.

If I only have a 2d array, I do not encounter a problem.


// Create the class
jclass intClass = env->FindClass("[I");

// Create 1st and 2nd array
jobjectArray array1 = env-> NewObjectArray(30, intClass, NULL)
jobjectArray array2 = env-> NewObjectArray(2, intClass, NULL)

// Create 3rd Array
jintArray array3 = env->NewIntArray(100);

// Put some data into array3
env-> SetIntArrayRegion(array3 , 0, 1, myBuffer);

// Add array 3 to array 2 and array 2 to array 1
env->SetObjectArrayElement(array2 , 0, array3);
env->SetObjectArrayElement(array1 , 0, array2 );

// Call the Java method
env->CallVoidMethod(obj, mid, array1 )


I have checked before calling the Java method that all 3 arrays are created
and have the correct sizes.

The example in Sheng Liang's book is only for 2d Arrays.

Any ideas ?

Many thanks.

Andreas


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com