Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crash in emulator 7.0: JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring

I got error android ndk on JniLibs code. I got error:

JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring

The following are detail error. I cannot post all because it is too long.

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)
.
.
.

JniLibs work well in emulator below this and show error in emulator version 7.0. The error occur when I remove app from recent apps and open the app again. Is it because of emulator or I did something wrong. I am very new with android ndk.

Thank for any helps.

like image 924
K.Sopheak Avatar asked Oct 30 '22 19:10

K.Sopheak


1 Answers

Finally, I know the cause of the problem. I got error on parameter of GetStringUTFChars and I was null. The syntax of this GetStringUTFChars is:

const char * GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy);

And I got null on paramter string, so solution is to check null before use this function. For example:

if (mystring == NULL){
  return NULL;
}
// function GetStringUTFChars

References: https://stackoverflow.com/a/15268628/5241603

like image 144
K.Sopheak Avatar answered Nov 11 '22 15:11

K.Sopheak