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
'Software > JAVA' 카테고리의 다른 글
java Thread 관련 (0) | 2013.12.05 |
---|---|
FT245BM을 리눅스 기반의 자바프로그램에서 이용하는 방법 (0) | 2013.12.05 |
(이전글 2006년) jni 사용예 (0) | 2013.12.05 |
(이전글 2006년) JNI (0) | 2013.12.05 |
(이전글 2009년) - 리눅스 환경에서 JAVA를 이용한 USB이용에 대한 문의드립니다. (0) | 2013.12.04 |