Unity Android 5.0上 JNI DETECTED ERROR IN APPLICATION: jclass is an invalid local reference
2017-06-07 16:32
686 查看
网上搜索的解决办法:
项目中
jclass o_class;
void initMeth(JNIEnv *env){
o_class = env->FindClass(项目中的java的对象类);
}
上面这个方法初始化了这个引用,除了android5.x之前貌似都不出问题,(6.x也不会出问题)
但是在android5.0上,我的另一个函数里使用
args = env->NewObjectArray(st->Count,o_class , 0); 运行到这行的时候,就会给我报 JNI DETECTED ERROR IN APPLICATION: jclass is an invalid local reference: 0xe340001d (0xdead4321)这个错误,说我的本地引用无效。 这个是与android5.0的GC机制有关系
把所有jclass a = env ->findclass(xxx);
的地方改成 jclass a ;
jclass tmp = env -> findclass(xxx);
a = (jclass)env->NewGlobalRef(tmp); 就搞定了!!!
新版本已经不允许全局使用findclass出来的局部引用了,
会被GC回收掉。所以必须new成全局引用才行。
之前没有把所有的jclass都改过来,所以还是会报错,
结果误以为是强转jclass无效。。。
项目中
jclass o_class;
void initMeth(JNIEnv *env){
o_class = env->FindClass(项目中的java的对象类);
}
上面这个方法初始化了这个引用,除了android5.x之前貌似都不出问题,(6.x也不会出问题)
但是在android5.0上,我的另一个函数里使用
args = env->NewObjectArray(st->Count,o_class , 0); 运行到这行的时候,就会给我报 JNI DETECTED ERROR IN APPLICATION: jclass is an invalid local reference: 0xe340001d (0xdead4321)这个错误,说我的本地引用无效。 这个是与android5.0的GC机制有关系
把所有jclass a = env ->findclass(xxx);
的地方改成 jclass a ;
jclass tmp = env -> findclass(xxx);
a = (jclass)env->NewGlobalRef(tmp); 就搞定了!!!
新版本已经不允许全局使用findclass出来的局部引用了,
会被GC回收掉。所以必须new成全局引用才行。
之前没有把所有的jclass都改过来,所以还是会报错,
结果误以为是强转jclass无效。。。
相关文章推荐
- Android之JNI DETECTED ERROR IN APPLICATION: illegal class name 'XXX'的错误解决方法
- JNI DETECTED ERROR IN APPLICATION: java_class == null
- cocos2dx JNI DETECTED ERROR IN APPLICATION: illegal class name 'XXX'的错误修复
- JNI DETECTED ERROR IN APPLICATION:java.lang.SecurityExceptionandroid--解决JNI安全权限异常
- JNI DETECTED ERROR IN APPLICATION: can't call void XXX on instance of java.lang.Class <XXX>解决方案
- JNI DETECTED ERROR IN APPLICATION: can't call void XXX on instance of java.lang.Class <XXX>解决方案
- JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0x12
- JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0x3f
- Android JNI DETECTED ERROR IN APPLICATION的解决
- Android error: JNI DETECTED ERROR IN APPLICATION
- JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception '
- 20100507 学习记录: Server Error in '/' Application. Object reference not set to an instance of an object
- Is there a way to add a badge to an application icon in Android?
- ByteBuffer.allocate()/ByteBuffer.allocateDirect()/JNI DETECTED ERROR IN APPLICATION: jarray was NULL
- Bug-JNI: JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception 'java.
- Android Error - JNI DETECTED ERROR IN APPLICATION
- Android:JNI Local Reference Changes in ICS
- junit,powermock单元测试时问题java.lang.ClassFormatError: Invalid length nnn in LocalVariableTable in class
- Compiler Error Message: CS0234: The type or namespace name 'BorderDetails' does not exist in the class or namespace 'Infragistics.WebUI.Shared' (are you missing an assembly reference?)