5

我有一个简单的问题,但在网上找不到解决方案。

我只想使用 JNI 从本机检索 Java 字符串。

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;
}

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;
}   
}

我被困住了。我认为这是一个愚蠢的错误...

你能帮我调查一下吗?

4

1 回答 1

12

您的方法签名不正确,缺少尾随分号:

 "()Ljava/lang/String;"    
 --------------------^
于 2012-11-19T23:03:03.373 回答