I cannot convert jstring to char array
JNIEXPORT jlong JNICALL Java_com_jnitest_JNI_getUid(JNIEnv * env,jobject thiz,jstring user){
const char *userName = (*env)->GetStringUTFChars(env,user,0);
(*env)->ReleaseStringUTFChars(env,user,userName);
FILE * f = fopen("/data/data/com.jnitest/p.txt","w");
if(f != NULL){
fprintf(f,"%c%c%c",userName[0],userName[1],userName[2]);
fclose(f);
}
return getUser(userName);
}
And in file p.txt i have this:
I have a mistake:
I'm releasing string before printing it to file.
This code:
(*env)->ReleaseStringUTFChars(env,user,userName);
should be at end of function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.