I have a simple issue but can not find a solution on the net.
I want simply to retrieve Java String from native using JNI.
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
works. But it is failing in GetMethodId
.
Here is my simple class declaration. I made it simpler than previously :)
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;
}
}
I am stuck. I think it is a stupid error...
Could you please help me to investigate it ?
Your method signature is incorrect, missing a trailing semicolon:
"()Ljava/lang/String;"
--------------------^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With