我想用jni将一个treemap从java传递到c。我调用本机方法:

public native int getEuklid(TreeMap<int,short[]> map);
static {
 System.loadLibrary("Euklid");
}

现在在我的c文件中,我想访问映射中的元素。我怎么做到的。这是我的c文件的头:
JNIEXPORT int JNICALL
Java_Main_getEuklid (JNIEnv *env, jobject o, jobject o2)

氧气是树形图。如何处理像java中的treemap这样的jobject?
编辑:
我的错在哪里?:
JNIEXPORT int JNICALL
Java_Main_getEuklid (JNIEnv *env, jobject o, jobject o2){
 jclass cls = env->GetObjectClass(o2) ;
 jmethodID mGetValue = env->GetMethodID(cls, "keySet","()Ljava/util/Set;");
 jobject value = env->CallObjectMethod(o2, mGetValue)

我变成了:
In function ‘Java_Main_getEuklid’:
11: error: request for member ‘GetObjectClass’ in something not a structure or union
12: error: request for member ‘GetMethodID’ in something not a structure or union
13: error: request for member ‘CallObjectMethod’ in something not a structure or union

我是c语言的新手,我想测试一些东西,希望你能帮我。

最佳答案

我认为这是纯C代码。你应该写些像:

(*env)->GetObjectClass(env, o2)

换句话说,RTFM,从这里开始http://en.wikipedia.org/wiki/Java_Native_Interface

关于java - JNI将树形图从Java传递到C,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16133902/

10-11 00:04