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!

How to return a 2-dimension string array via JNI

843829May 21 2009 — edited May 21 2009
Hi,

I have a question to return a 2-dimension string array via JNI. Here is my code snippet:
        jobjectArray result;	
	result = env->NewObjectArray(len, env->FindClass("java/lang/String"), NULL);	//create an array for the 1st dimension
	
	for(i=0; i<len; i++) {
		jobjectArray iarr = env->NewObjectArray(len2, env->FindClass("java/lang/String"), NULL); //intermediate array for the 2nd dimension
if (iarr == NULL) {
return NULL;
}

for(int j=0; j<len2[i]; j++) {
env->SetObjectArrayElement(iarr, j, env->NewStringUTF("AAA"));
}
env->SetObjectArrayElement(result, i, iarr);
env->DeleteLocalRef(iarr);
}
return result;
When variable i=1, the VM is always crashing at this line: "iarr = env->NewObjectArray(len2, env->FindClass("java/lang/String"), NULL); ". But len2[i] is greater than 0, what's the problem in my code?

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2009
Added on May 21 2009
3 comments
342 views