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字符。因此需要在调用函数之前,对接口传入的字符串进行过滤,过滤函数如下:
{
const char* origBytes = bytes;
if (bytes == NULL) {
return -1;
}
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: {
/*printf("****JNI WARNING: illegal start byte 0x%x\n", utf8);*/
return -1;
}
case 0x0e: {
// Bit pattern 1110, so there are two additional bytes.
utf8 = *(bytes++);
if ((utf8 & 0xc0) != 0x80) {
/*printf("****JNI WARNING: illegal continuation byte 0x%x\n", utf8);*/
return -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) {
/*printf("****JNI WARNING: illegal continuation byte 0x%x\n", utf8);*/
return -1;
}
break;
}
}
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
int checkUtfString(const char* bytes)
{
const char* origBytes = bytes;
if (bytes == NULL) {
return -1;
}
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: {
/*printf("****JNI WARNING: illegal start byte 0x%x\n", utf8);*/
return -1;
}
case 0x0e: {
// Bit pattern 1110, so there are two additional bytes.
utf8 = *(bytes++);
if ((utf8 & 0xc0) != 0x80) {
/*printf("****JNI WARNING: illegal continuation byte 0x%x\n", utf8);*/
return -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) {
/*printf("****JNI WARNING: illegal continuation byte 0x%x\n", utf8);*/
return -1;
}
break;
}
}
}
return 0;
}
|
发布者
默默
默默码农 查看所有由默默发布的文章
#########################################################################################################
newStringUTF出现input is not valid Modified UTF-8错误解决办法
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
JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xfe的更多相关文章
- crash - JNI WARNING: input is not valid modified utf-8: illegal continuation byte
the key point is "Modified UTF-8" is not like "Regular UTF-8", a legal Rgular UT ...
- Error configuring application listener of class。。。NoClassDefFoundError。。某Listener 之启动tomcat报错
当你启动tomcat的时候如果报类似下面的错误: WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to ' ...
- 【.net部署】Server Error in '/' Application.错误解决方案
报错: Server Error in '/' Application.---------------------------------------------------------------- ...
- AspNetPager控件报错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$Aspnetpager1_input问题解决[摘]
高版本IE,如IE10或者IE11在浏览页面时出现错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$ ...
- 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...
- Server Error in '/' Application
在服务器部署了网站,然后访问的时候出现异常 Server Error in '/' Application,一般这样的异常都是不明确的,我们应当把网站根目录web.config<custom ...
- IIS出现Server Error in '/' Application.CS0016的解决办法
这两天一直在弄IIS的事,全都是报错,网上找了好多资料,也尝试了很多,终于在几分钟之前把困扰了我一周的麻烦给解决了,现整理出来,希望对大家有用,闲话少说,直接上图了 Server Error in ' ...
- 使用Maven构建javaWeb项目时,启动tomcat出错:严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.conte
在初学使用maven构建javaWeb的项目的时候,启动tomcat加载时,总是提示如下错误,辛苦一番终于找到解决办法. 严重: Error configuring application liste ...
- tomcat : Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException:
错误 严重: Error configuring application listener of class org.springframework.web.context.ContextLoader ...
随机推荐
- shp系列(三)——利用C++进行DBF文件的读(打开)
1.DBF文件要点 DBF文件又叫属性文件,也叫dBASE文件,文件后缀是.dbf,实际上ArcGIS打开后的属性表就是DBF的信息.DBF文件遵循以下几个条件: 每个要素在表中必须要包含一个与之相对 ...
- Endnote导入共享数据
Endnote导入共享数据 Endnote是我们经常使用的参考文献管理工具.但是,在云计算还不是很普及的今天,往往每台电脑上都有自己的endnote数据库.这样,换了电脑,要使用同样的参考文献数据时, ...
- .NET前后台-JS获取/设置iframe内对象元素并进行数据处理
转载请注明出处:果冻栋吖 这个主要是修改H3BPM一个批量审批的功能时候做的.先看下图: H3自带了批量审批的功能,也就是按钮1,有审批意见3,但是如果3里边不填写内容点击1之后,效果就是表单里边没有 ...
- linux下使用bcp备份sybase数据
命令|数据库名|表名|导出到|文件名|格式|sybase服务名|数据库登录名 |字符集 bcp dbname..tablename out filename -n -Sgfdmhk -UISISMan ...
- 剖析Promise内部结构,一步一步实现一个完整的、能通过所有Test case的Promise类
本文写给有一定Promise使用经验的人,如果你还没有使用过Promise,这篇文章可能不适合你,建议先了解Promise的使用 Promise标准解读 1.只有一个then方法,没有catch,ra ...
- WordPress浏览次数统计插件:WP-Postviews使用
WP-Postviews使用 1.要让你的博客在页面上显示浏览次数,你需要修改你博客当前使用的主题,在主循环中插入以下代码: 1 <?php if(function_exists('the_vi ...
- Android java处理保留小数点后几位
方式一: 四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = ...
- 基于S3C2440数码相框
[参考]韦东山 教学笔记 1. 程序框架1.1 触摸屏: 主按线程,通过socket发给显示进程 --------------------------- 封装事件:ts线程 按键线程 -------- ...
- vue-阻止事件冒泡-开启右键-键盘类事件
一: 阻止事件冒泡 布局: 当点击按钮时,会触发button的click 也会触发父级的方法 <div id="box"> <div @click="p ...
- mvvm模式和mvc模式 概述总结对比
1.mvc模式简介: MVC的全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,是一种软件设计典范.例如: angular ...