problem in JNI while creating the string by newstingutf

124 views
Skip to first unread message

ani

unread,
Sep 22, 2010, 2:05:01 PM9/22/10
to android-ndk
Hi all,
Actually i want to call java function from JNI which is having
an argument string. For that I am passing char* from native into JNI
and trying to convert by using NewStringUTF but at that time program
get crashed and error
is JNI warning:illegal start byte 0xef and display the string.
if anyone know the reason please let me know.

Tim Mensch

unread,
Sep 22, 2010, 2:14:53 PM9/22/10
to andro...@googlegroups.com
UTF-8 only allows certain bytes to be the "first" in a set of bytes that
refer to a code point. You've got a string that's not legal UTF-8. You
can give it any 7-bit ASCII values without conversion, but 0xEF would
only be valid after certain byte values in UTF-8.

See: http://en.wikipedia.org/wiki/UTF-8

If your source file is encoded in something other than UTF-8, that could
be the problem. You may also be missing a NULL terminator, I suppose,
and the 0xEF is just the first garbage that failed the UTF-8 check.

Tim

fadden

unread,
Sep 22, 2010, 7:34:29 PM9/22/10
to android-ndk
On Sep 22, 11:14 am, Tim Mensch <tim.men...@gmail.com> wrote:
> See:http://en.wikipedia.org/wiki/UTF-8

See also: http://download.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html#wp16542

This page has the definition of "Modified UTF-8" as recognized by the
VM. The main difference is that '\0' is represented as a multi-byte
value, so that you can use C-style strings. The other difference is
that the 4-byte format isn't recognized.

The key thing to remember is that JNI provides NewStringUTF, not
NewStringASCII or NewStringISOLatin1. If you pass in a non-UTF-8
string, the VM will convert it to something other than what you had in
mind. (Or, if you have CheckJNI enabled, complain bitterly and
abort.)
Reply all
Reply to author
Forward
0 new messages