NDK开发错误 use of invalid jobject 0x7fb147b460

JNI中直接返回C/C++的字符串时会报如下错误

 JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0x7fb147b460
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]     from java.lang.String com.example.testndkeclipse.JniClient.AddStr(java.lang.String, java.lang.String)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399] "main" prio=5 tid=1 Runnable
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   | group="main" sCount=0 dsCount=0 obj=0x764a95c0 self=0x7fb247c400
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   | sysTid=21402 nice=0 cgrp=default sched=0/0 handle=0x7fb62e92c0
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   | state=R schedstat=( 144816922 6913689 138 ) utm=8 stm=6 core=4 HZ=100
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   | stack=0x7fea3da000-0x7fea3dc000 stackSize=8MB
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   | held mutexes= "mutator lock"(shared held)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at com.example.testndkeclipse.JniClient.AddStr(Native method)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at com.example.testndkeclipse.MainActivity.onClick(MainActivity.java:71)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at android.view.View.performClick(View.java:5317)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at android.view.View$PerformClick.run(View.java:21648)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at android.os.Handler.handleCallback(Handler.java:815)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at android.os.Handler.dispatchMessage(Handler.java:104)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at android.os.Looper.loop(Looper.java:207)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at android.app.ActivityThread.main(ActivityThread.java:5915)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at java.lang.reflect.Method.invoke!(Native method)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
07-12 11:35:02.133: A/aoc(21402): aliyunos/aoc/vm/jni/java_vm_ext.cc:399]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:816)

需要将C/C++中的字符串转换为中间层jstring返回

jstring result = (*env)->NewStringUTF(env,n_str_point);
return result;//需要转换为中间层jstring返回

NdkDemo代码已上传至Github

如有不正支出,欢迎留言交流!
我的GitHub
我的CSDN
我的简书
开发笔记

你可能感兴趣的:(NDK/JNI/C/C++)