当前位置: 首页 > 知识库问答 >
问题:

模拟器7.0中的应用程序崩溃:JNI在应用程序中检测到错误:GetStringUTFChars接收到空jstring

袁泓
2023-03-14
10-05 17:12:01.100 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring
10-05 17:12:01.100 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]     in call to GetStringUTFChars
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]     from java.lang.String com.example.myapp.othercode.PassCodeUtil.genPassCode(android.content.Context)
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470] "main" prio=5 tid=1 Runnable
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]   | group="main" sCount=0 dsCount=0 obj=0x75518a50 self=0x7ffef3695a00
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]   | sysTid=3773 nice=0 cgrp=default sched=0/0 handle=0x7ffef7ff9b40
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]   | state=R schedstat=( 0 0 0 ) utm=3 stm=2 core=0 HZ=100
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]   | stack=0x7fffa7798000-0x7fffa779a000 stackSize=8MB
10-05 17:12:01.101 3773-3773/com.example.myapp A/art: art/runtime/java_vm_ext.cc:470]   | held mutexes= "mutator lock"(shared held)
.
.
.

谢谢你的帮助。

共有1个答案

苍兴怀
2023-03-14

终于知道问题的原因了。GetStringUTFChars参数出错,为空。此GetStringUTFChars的语法为:

常量char*GetStringUTFChars(JNIEnv*env,jstring字符串,jboolean*iscopy);

并且我在参数字符串上得到了null,所以解决方法是在使用这个函数之前检查null。例如:

if (mystring == NULL){
  return NULL;
}
// function GetStringUTFChars
 类似资料: