NDK中的NewStringUTF错误问题

NDK中的NewStringUTF错误问题

我的错误:
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 !");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值