Hi
Hope this code answers your question ..
Best of luck.
--Jools
JNIEXPORT void JNICALL Java_MyFunction
(JNI Env *env, jobject my_object,jobjectArray my_array)
{
// It's always a good Idea to get the length of the array first.
jint len = (*env)->GetArrayLength( my_array );
// Check that it does have at least one element.
if ( len < 1 ) {
return;
}
// Get a jstring object from the array/
jstring jstr = (jstring) (*env)->GetObjectArrayElement(env,
my_array, 0);
// Get a pointer to the string.
jboolean iscpy;
const char *cstr = (*env)->GetStringUTFChars( jstr, iscpy );
// lets see what it is :-)
printf("%s\n", cstr );
// Check to see if we need to release the string.
if ( iscpy == JNI_TRUE )
(*env)->ReleaseStringUTFChars( jstr, cstr );
// Need to release the local reference.
// If you are in a loop, don't forget to release each reference
// or you will run out of local references :-(
(*env)->DeleteLocalRef( jstr );
}
>Hi Jini users,
>Excuse me for asking this question !!.It is a part of my Jini Service
>which uses Java Native interafce with C.I am new to Java, I have written
>a small java code which calls a C function by passing a string
>array(2D). Following is the native function C code which prints garbage
>when I execute 'java' of my java class. It is perfectly printing the
>length of the array but not the contents of the arrya.How to access the
>contents of string array and also how
>to return a 2D array from C to java and read in java?.
>-------------------------------------------------------------------------
>...
>JNIEXPORT void JNICALL Java_MyFunction
>(JNI Env *env, jobject my_object,jobjectArray my_array)
>{
> jobject value1 = (*env)->GetObjectArrayElement(env, my_array, 1);
> printf("%s\n",value1);
>}
>-------------------------------------------------------------------------
>Thanks in advance,
>Nagaraj
>
>
>----------------------------------------------------------------------
>To UNSUBSCRIBE, email to [EMAIL PROTECTED]
>with a subject of "unsubscribe". Trouble? Contact
>[EMAIL PROTECTED]
>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]