我的错误:
error: no matching function for call to '_JNIEnv::NewStringUTF(JNIEnv*&, char [5])'
jstr=env->NewStringUTF(env,buf);
JNIEXPORT jstring JNICALL Java_com_example_testjnipro_MainActivity_sayHello
(JNIEnv * env, jobject thiz)
{
//return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI ");
return env->NewStringUTF( "Hello from JNI ! Compiled with ABI ");
}
C++中用:
return env->NewStringUTF( "Hello from JNI ! Compiled with ABI ");
注意:只有一个参数!!
C中用:
return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI ");
注意:有两个参数!!
Depending on whether the native code is a C or C++ source file, the syntax for calling JNI functions differs.
In C code, JNIEnv is a pointer to JNINativeInterface structure. This pointer needs to be
dereferenced first in order to access any JNI function. Since the JNI functions in C code do not know
the current JNI environment, the JNIEnv instance should be passed as the first argument to each JNI
function call, like so:
return (*env)->NewStringUTF(env, "Hello from JNI !");
In C++ code, JNIEnv is actually a C++ class instance. JNI functions are exposed as member
functions. Since JNI methods have access to the current JNI environment, the JNI method calls do
not require the JNIEnv instance as an argument. In C++, the same code looks like
return env->NewStringUTF("Hello from JNI !");