On Sep 15, 7:52 am, dmitry chernov <
diman4ik.cher...@gmail.com> wrote:
> Finally it came to this variant :
>
> jstring
> Java_com_example_hellojni_HelloJni_stringNative(JNIEnv *env, jobject obj)
> {
> const char *str = "я строка";
This is doing it the hard way.
If the input string is UTF-8, you can use NewStringUTF. If it's some
other encoding format (e.g. iso-latin1), NewStringUTF won't know what
to do with it. Can you print the binary representation of "str"?
e.g.:
int main() {
const char* str = "я строка";
while (*str != '\0') {
printf("%02x ", (unsigned char) *str++);
}
putchar('\n');
return 0;
}
The mail message you sent used UTF-8 encoding, so when I copied &
pasted the string out of it I got:
d1 8f 20 d1 81 d1 82 d1 80 d0 be d0 ba d0 b0
If yours comes out differently, you have a problem with your source
file encoding (see Tim Mensch's message).
> But this time Dalvik VM crashes on NewObjecy call. What is it? No error
> messages in log. It simply writes that Dalvik VM is aborting.
What appears in the log above the message that indicates the VM is
aborting? What does the failure message itself look like?
My guess is that passing the C constant "ru_RU" instead of a String
object is causing the failure. If CheckJNI is enabled, recent
versions of the VM will detect the bad object reference and abort
after reporting the problem. If it's not enabled, the VM will
probably crash with a segmentation fault when it tries to traverse the
non-existent object header.
Also, if you turn CheckJNI on, strings passed to NewStringUTF are
checked for UTF-8 validity.