use*_*153 3 java-native-interface android
我有一个简单的问题,但无法在网上找到解决方案.
我想简单地使用JNI从本机检索Java String.
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
void * my_lib_handle;
jmethodID mid;
jstring resultString;
JNIEnv *env;
int status;
__android_log_write(ANDROID_LOG_DEBUG,"JNI", "> JNI_OnLoad");
status = (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_4);
if(status < 0){
__android_log_write(ANDROID_LOG_DEBUG,"JNI", "failed to get JNI environment");
status = (*vm)->AttachCurrentThread(vm, (void**)&env, NULL);
if(status < 0){
__android_log_write(ANDROID_LOG_DEBUG,"JNI", "failed to attach to current thread");
return;
}
}
jclass handlerClass = (*env)->FindClass(env, "com/mypackage/JniInterface");
if (handlerClass == NULL) {
__android_log_write(ANDROID_LOG_DEBUG,"JNI", "can not find the class JniInterface ");
return;
}
mid = (*env)->GetMethodID(env, handlerClass, "getCert", "()Ljava/lang/String");
if (mid == NULL) {
__android_log_write(ANDROID_LOG_DEBUG,"JNI", "can not find the method getCert");
return;
}
Run Code Online (Sandbox Code Playgroud)
FindClass作品.但它失败了GetMethodId.
这是我简单的类声明.我比以前简单:)
package com.mypackage;
public class JniInterface {
private static String cert;
private static String key;
public JniInterface(){
}
public static String getCert() {
return cert;
}
public static void setCert(String cert) {
JniInterface.cert = cert;
}
public static String getKey() {
return key;
}
public static void setKey(String key) {
JniInterface.key = key;
}
}
Run Code Online (Sandbox Code Playgroud)
我被卡住了.我认为这是一个愚蠢的错误......
你能帮我调查一下吗?
tec*_*age 11
您的方法签名不正确,缺少一个尾随分号:
"()Ljava/lang/String;"
--------------------^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4627 次 |
| 最近记录: |