JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe

JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe

在使用Jni的JNIEnv->NewStringUTF的时候抛出了异常"JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe "。网上搜索了一下,这个异常是由于Java虚拟机内部的dalvik/vm/CheckJni.c中的checkUtfString函数抛出的,并且JVM的这个接口明确是不支持四个字节的UTF8字符。因此需要在调用函数之前,对接口传入的字符串进行过滤,过滤函数如下:

参考链接 android jni中 utf-8的check

发布者

 

默默

默默码农 查看所有由默默发布的文章

 

 

#########################################################################################################

newStringUTF出现input is not valid Modified UTF-8错误解决办法

2013年10月12日 ⁄ 综合 ⁄ 共 883字 ⁄ 字号 ⁄ 评论关闭
 

JNI调用newStringUTF时遇到不认识的字符串就直接出错退出~~,网上原因是dalvik/vm/CheckJni.c里面的checkUtfString函数检查通不过.找了半天没找到修正办法,把这个函数改了下,当做一个修正函数,下面是代码

 

void correctUtfBytes(char* bytes) {
  char three = 0;
   while (*bytes != '\0') {
	   unsigned char utf8 = *(bytes++);
	   three = 0;
	   // 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.
			*/
		   *(bytes-1) = '?';
		   break;
	   case 0x0e:
		   // Bit pattern 1110, so there are two additional bytes.
		   utf8 = *(bytes++);
		   if ((utf8 & 0xc0) != 0x80) {
			   --bytes;
			   *(bytes-1) = '?';
			   break;
		   }
		   three = 1;
		   // 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) {
			   --bytes;
			   if(three)--bytes;
			   *(bytes-1)='?';
		   }
		   break;
	   }
   }
}

http://www.xuebuyuan.com/1240531.html
http://www.mobibrw.com/2016/2859
posted @   a318013800  阅读(5573)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示