본문 바로가기

Software/JAVA

(이전글 2006년) Java Technology Forums - Error message in JNI

반응형

Error message in JNI   
 Oct 28, 2003 7:02 PM


 

 

Hi ALL:

I want to pass an array of strings from Java to a native method written in
C.Below is my code

JNIEXPORT void JNICALL Java_init (JNIEnv *env, jobject jobj,jobjectArray jfilename, jint jlength){jsize arrsize = env->GetArrayLength(jfilename);jstring elem;char **cstr;int i,j;cstr = (char **) maloc(arrsize * sizeof(char*));for (i=0 ; i< arrsize ; i++){elem = (jstring)env->GetObjectArrayElement(jfilename,i);cstr[i] = (char *)env->GetStringUTFChars(elem,NULL);}for (j=0 ; j<arrsize ; j++){printf("The char is %s\n",cstr[j]);}  }

But there are some error message occurs
KeywordAnalyzer.c:In function `Java_init':KeywordAnalyzer.c:12: request for member `GetArrayLength'in something not a structure or unionKeywordAnalyzer.c:22: request for member `GetObjectArrayElement'in something not a structure or unionKeywordAnalyzer.c:23: request for member `GetStringUTFChars'in something not a structure or union 

Can anyone tell me what happens???
Thanks in advance>

 

 

 

 

If you really mean C and not C++, then you can't use env->Get....

you need to use the GetArrayLength(env,...); form.

Take a look at the docs for more details, or rename you file to c++ and recompile.

 

 

 

Thanks for your help , armalcolm
 Now I success after I correct the code.Below is the code

JNIEXPORT void JNICALL Java_init (JNIEnv *env, jobject jobj,jobjectArray jfilename, jint jlength){ jstring elem;jboolean iscopy;char **cstr;int i,j;int length;length = jlength;printf("The size of array is %d\n",length);cstr = (char **) malloc(length * sizeof(char*));for (i=0 ; i< length ; i++){ elem = (*env)->GetObjectArrayElement(env,jfilename,i);cstr[i] = (*env)->GetStringUTFChars(env,elem,_}for (j=0 ; j<length ; j++){printf("The char is %s\n",cstr[j]);}  }


Can I ask you one more question??
When I execute "printf("The char is %s\n",cstr[j]);"
The strings display in screen are some string I can't understand
However, I have used GetStringUTFChars() method to change 8 bits characters from 16 bits unicode.Do I used this method wrongly???
Thnaks
 >



출처 : http://forum.java.sun.com/thread.jspa?forumID=52&threadID=458918

반응형