gpt4 book ai didi

android - JNI GetMethodId 返回空

转载 作者:太空宇宙 更新时间:2023-11-03 11:44:35 25 4
gpt4 key购买 nike

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

我只想使用 JNI 从 native 检索 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;
}
}

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

你能帮我调查一下吗?

最佳答案

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

 "()Ljava/lang/String;"    
--------------------^

关于android - JNI GetMethodId 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13463665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com