I want to convert jchar array to char array in JNI ? How should i do it :
JNI Code Snippet :
jcharArray arr = (jcharArray) (*env)->CallObjectMethod(env, obj, mid);
int count = (*env)->GetArrayLength(env, arr);
jchar* chars = (*env)->GetCharArrayElements(env, arr, 0);
char reg_chal= chars[1];
char reg_chal= chars[1] statement inserts garbage value into reg_chal.
How to resolve this issue. Thanks in advance.
If you’ll note the JNI documentation, a
jcharis an unsigned 16 bit value (which makes sense, as java characters are represented by UTF-16.) If you want an 8 bit value (the size of a Cchar) you should be usingjbyte.