我有一个简单的问题,但在网络上找不到解决方案。
我只想使用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;
}
}
我卡住了。我觉得这是一个愚蠢的错误......
你能帮我调查一下吗?