Array Elements are missing on including ReleaseStringUTFChars in my code
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Prakher_Singhal
Posted On:   Thursday, May 7, 2009 03:48 AM

Hello, I am creating a small application to communicate to C language programs through java using Netbeans IDE. I'm passing an String array from java to a C program. I'm using ReleaseStringUTFChars in my code and trying to print the array elements. While printing, Array elements are missing. If I'm removing ReleaseStringUTFChars from my code, the array elements are getting printed on command line. Its written in a JNI document that Using of ReleaseStringUTFChars is must. Below is my code fragment.... JNIEXPORT void JNICALL Java_my_1arrayviewer_My_1ArrayViewerCode_calcParamInterface (JNIEnv *env, jobject myJClassObj, jobjectArray myJObjArray, jint myInt) { //   More>>

Hello,

I am creating a small application to communicate to C language programs through java using Netbeans IDE.

I'm passing an String array from java to a C program. I'm using ReleaseStringUTFChars in my code and trying to print the array elements. While printing, Array elements are missing. If I'm removing ReleaseStringUTFChars from my code, the array elements are getting printed on command line. Its written in a JNI document that Using of ReleaseStringUTFChars is must. Below is my code fragment....





JNIEXPORT void JNICALL Java_my_1arrayviewer_My_1ArrayViewerCode_calcParamInterface
(JNIEnv *env, jobject myJClassObj, jobjectArray myJObjArray, jint myInt) {


// C Variables

int c_int;

c_int = (int)myInt;

char *arrayOfElements[c_int];

const char *temp;

int i;



// Java Variables

jstring col;




for (i = 0; i < c_int; i++)

{

col = (*env)->GetObjectArrayElement(env, myJObjArray, i);

temp = (*env)->GetStringUTFChars(env, col, 0);

// (*env)->ReleaseStringUTFChars(env, col, temp);

arrayOfElements[i] = temp;

printf("Details[%d] : %s
",i,arrayOfElements[i]);

}




}




Can anyone please give my the solution for this problem?

   <<Less
About | Sitemap | Contact