【发布时间】:2014-07-22 09:52:14
【问题描述】:
为了使用 JNI 实现对 java 代码的 C 回调,我遵循了 here 和 here 的建议,并调整了我的本机方法实现以存储对稍后回调所需对象的引用:
JavaVM * g_vm;
jobject g_obj;
jmethodID g_mid;
//More code here
JNIEXPORT jboolean JNICALL
Java_a_B_initialize(JNIEnv * env, jobject obj)
{
g_obj = env->NewGlobalRef(obj);
jclass g_clazz = env->GetObjectClass(g_obj);
if (g_clazz == NULL) {
printf("Failed to find class");
}
g_mid = env->GetMethodID(g_clazz, "callback", "(I)V");
if (g_mid == NULL) {
printf("Unable to get method ref");
}
但是,这无法编译,我收到错误消息:
Left of '-> NewGlobalRef' must point to struct/union
Left of '-> GetObjectClass' must point to struct/union
Left of '-> GtMethodID' must point to struct/union
我不明白这些错误信息。我的代码有什么问题?
【问题讨论】:
-
您是否忘记了
#include? -
我的包含看起来像这样:#include
#include #include #include #include "a_B.h" 应该还有更多吗? -
你能粘贴编译器的完整输出吗?
标签: java c java-native-interface