我有以下功能:
JNIEXPORT void Java_com_vidyo_vidyomod_services_VidyoCommands_Login(JNIEnv* env, jobject javaThis,
jstring vidyoportalName, jstring userName, jstring passwordName, jobject callback) {
FUNCTION_ENTRY;
const char *portalC = (*env)->GetStringUTFChars(env, vidyoportalName, NULL);
const char *usernameC = (*env)->GetStringUTFChars(env, userName, NULL);
const char *passwordC = (*env)->GetStringUTFChars(env, passwordName, NULL);
jclass loginClass = (*env)->GetObjectClass(env, callback);
VIDYO_CLIENT_LOG_INFO_FORMATTED("Login() NDKMETHOD1 Starting Login Process BEFORE %d" , loginClass);
methodClass = (*env)->GetMethodID(env, loginClass, "onResponse", "(Ljava/lang/String;Ljava/lang/String;)V");
VIDYO_CLIENT_LOG_INFO_FORMATTED("Login() NDKMETHOD1 Starting Login Process BEFORE 2%d" , methodClass);
VIDYO_CLIENT_LOG_INFO("Login() NDKMETHOD Starting Login Process");
VidyoClientInEventLogIn event = {0};
strlcpy(event.portalUri, portalC, sizeof(event.portalUri));
strlcpy(event.userName, usernameC, sizeof(event.userName));
strlcpy(event.userPass, passwordC, sizeof(event.userPass));
VIDYO_CLIENT_LOG_INFO_FORMATTED("Login() NDKMETHOD login with portalUri %s user %s ", event.portalUri, event.userName);
VidyoClientSendEvent(VIDYO_CLIENT_IN_EVENT_LOGIN, &event, sizeof(VidyoClientInEventLogIn));
FUNCTION_EXIT;
}
我得到了一个out事件,我试图像这样处理(调用我试图发送给NDK的接口的onResponse方法):
// Send message to Client/application
VIDYO_CLIENT_LOG_INFO("GuiOnOutEvent NDKMETHOD VIDYO_CLIENT_OUT_EVENT_SIGNED_IN sign in successful");
jboolean isAttached;
VIDYO_CLIENT_LOG_INFO("GuiOnOutEvent NDKMETHOD VIDYO_CLIENT_OUT_EVENT_SIGNED_OUT sign in successful2");
JNIEnv *env;
VIDYO_CLIENT_LOG_INFO("GuiOnOutEvent NDKMETHOD VIDYO_CLIENT_OUT_EVENT_SIGNED_OUT sign in successful3");
env = getJniEnv(&isAttached);
VIDYO_CLIENT_LOG_INFO("GuiOnOutEvent NDKMETHOD1 VIDYO_CLIENT_OUT_EVENT_SIGNED_IN mid has been initialised");
jstring js = (*env)->NewStringUTF(env, "");
VIDYO_CLIENT_LOG_INFO("GuiOnOutEvent NDKMETHOD1 VIDYO_CLIENT_OUT_EVENT_SIGNED_IN js string created");
(*env)->CallVoidMethod(env, applicationJniObj, methodClass, js , js);
我这样调用登录方法:
CallbackFromNDK back = new CallbackFromNDK() {
@Override
public void onResponse(String code, String response) {
Log.i("","GuiOnOutEvent NDKMETHOD got out of it");
Utils.disposeDone = true;
loginResolved();
}
};
((VMBaseActivity)getActivity()).app.vidyoCommands.Login(VidyoModApplication.prefManager.getPortal(getActivity()), user, pass, back);
这是来自我的LoginFragment,已打包:package com.vidyo.vidyomod.activities;
我的界面有这个包:package com.vidyo.vidyomod.interfaces;
但是因为我在登录片段中创建CallbackFromNDK时尝试调用登录,我甚至得到back.getClass().toString()
这个:com.vidyo.vidyomod.activities.LoginFragment$2
在我的ndk代码中,它会转到(*env)->CallVoidMethod(env, applicationJniObj, methodClass, js , js);
并收到此错误:
06-06 17:17:10.335: E/art(26772): JNI DETECTED ERROR IN APPLICATION: can't call void com.vidyo.vidyomod.activities.LoginFragment$2.onResponse(java.lang.String, java.lang.String) on instance of com.vidyo.vidyomod.VidyoModApplication
06-06 17:17:10.335: E/art(26772): in call to CallVoidMethod
06-06 17:17:10.336: E/art(26772): "Thread-1652" prio=5 tid=23 Runnable
06-06 17:17:10.336: E/art(26772): | group="main" sCount=0 dsCount=0 obj=0x32dbe0a0 self=0xedc5fa00
为什么不让我称这个功能?