JNI笔记

1、写了个简单的方法,打算从c中返回一个字符串。c中代码为:

JNIEXPORT jstring JNICALL Java_com_example_jnitest_getstring
  (JNIEnv *e, jclass j) {
   return "from jni";      
}

  java中代码:

public static native String getString();

  运行的时候是会报错的,错误信息:Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 2050 (example.jnitest)

      这里是由于类型匹配错误导致。在c代码中返回类型应如下:

JNIEXPORT jstring JNICALL Java_com_example_jnitest_getstring
  (JNIEnv *e, jclass j) {
   return (*e)->NewStringUTF(e, "from jni");   /* should be this */
}

to be continue,,

原文地址:https://www.cnblogs.com/ivan-aldrich/p/4551281.html