blog.csdn.net/livingpark

导致这一错误是android中chechjni.c里面的函数static void checkUtfString(JNIEnv* env, const char* bytes, bool nullOk,
const char* func)对字符串进行检查,不符合它的标准就回出错。

解决方法是使用字符串之前进行转换,使字符串符合要求,以下函数是一种方案,根据checkUtfString函数改写。

int char2UTF(char* cp)
{
char* bytes;
bytes = cp;
while (*bytes != '/0')
{
unsigned char utf8 = *(bytes++);
// Switch on the high four bits.
switch (utf8 >> 4) {
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07: {
// Bit pattern 0xxx. No need for any extra bytes.
break;
}
case 0x08:
case 0x09:
case 0x0a:
case 0x0b:
case 0x0f: {
/*
* Bit pattern 10xx or 1111, which are illegal start bytes.
* Note: 1111 is valid for normal UTF-8, but not the
* modified UTF-8 used here.
*/
LOGW("JNI WARNING: illegal start byte 0x%x/n", utf8);
*((unsigned char *)(bytes-1)) = 0x3f;
break;
}
case 0x0e: {
// Bit pattern 1110, so there are two additional bytes.
utf8 = *(bytes++);
if ((utf8 & 0xc0) != 0x80) {
LOGW("JNI WARNING: illegal continuation byte 0x%x/n", utf8);
*((unsigned char *)(bytes-1)) = 0x80;
}
// Fall through to take care of the final byte.
}
case 0x0c:
case 0x0d: {
// Bit pattern 110x, so there is one additional byte.
utf8 = *(bytes++);
if ((utf8 & 0xc0) != 0x80) {
LOGW("JNI WARNING: illegal continuation byte 0x%x/n", utf8);
*((unsigned char *)(bytes-1)) = 0x80;
}
break;
}
}
}

return 0;
}

更多相关文章

  1. android openmax&surfaceflinger
  2. input 按键分发
  3. EvilCode的专栏╭☆╯ -- Android/Linux DRIVER
  4. 【Android】android的基本UI操作(2)以及小结
  5. Android(安卓)NDK学习笔记8-JNI的访问域
  6. Android中调用Paint的measureText()方法取得字符串显示的宽度值
  7. Android之三角函数
  8. Android(安卓)应用软件开发(四)菜单控件
  9. android strings.xml转义字符, 注意细节解决

随机推荐

  1. android:layout_gravity 和 android:grav
  2. Android平台开发-Android(安卓)HAL devel
  3. Android中资源文件的Shape使用总结
  4. Android(安卓)平台基础开发简介
  5. Android(安卓)Studio Android(安卓)UI控
  6. Android手机操作系统中的常用术语
  7. 记录一下八款开源 Android(安卓)游戏引擎
  8. Android(安卓)核心分析(13) -----Android
  9. android:layout_gravity 和 android:grav
  10. android:layout_gravity 和 android:grav