如何转换jchar在JNI为char在Android开发? [英] How to convert jchar to char in JNi in Android development?
本文介绍了如何转换jchar在JNI为char在Android开发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想转换jchar数组字符数组在JNI?我应该怎么做:
I want to convert jchar array to char array in JNI ? How should i do it :
JNI code段:
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];
字符reg_chal =字符[1]语句将垃圾值到reg_chal。 如何解决这个问题。先谢谢了。
char reg_chal= chars[1] statement inserts garbage value into reg_chal. How to resolve this issue. Thanks in advance.
推荐答案
如果你注意到的 JNI文档,一个 jchar
是一个无符号16位值(这是有道理的,因为Java字符再由psented $ P $ UTF-16)。如果你想要一个C 字符
),你应该使用的8位值(尺寸 jbyte
。
If you'll note the JNI documentation, a jchar
is 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 C char
) you should be using jbyte
.
这篇关于如何转换jchar在JNI为char在Android开发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文