Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI: Multi-dimensional (3-D) Array [][][]

843829Feb 21 2006 — edited Feb 22 2006
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.

Andy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2006
Added on Feb 21 2006
2 comments
661 views