Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI wchar_t problem (unix platforms)

843829Mar 26 2008 — edited Sep 1 2009
Hi all,

i have such kind of broblem on unix platforms. I have unicode string in JNI and when i create jstring and return it to java the string is not completed. So,

/////////////////////////////////////////////////
wchar_t name[50] = L"Ob als Sch�ler";
jstring objectName = NULL;
len = wcslen(name);
objectName = (*env)->NewString(env, name, len);
return objectName;
////////////////////////////////////////////////

I receive in Java "Ob als". I receive warning when compile the c code, theat argument #2 is not compatible with prototype. This happened because the second parameter is unsigned short, and wchar_t, which i passed, is four bytes. How can i fix this problem with wide char string? Is it a good idea to convert wchar_t string to char string and after that to create NewStringUTF? I noticed that when the len is twice bigger i.e. len = 2*wcslen(name) the string which is created is full. Is it correct to use this function with twice more length?
Thanks,
Valentin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 29 2009
Added on Mar 26 2008
13 comments
3,737 views