JNI将树形图从java传递给c

时间:2013-04-21 17:11:34

标签: java c java-native-interface

我想用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)

其中o2是树形图。我如何处理该作业,如java中的树形图?

编辑:

我的错在哪里?:

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的新人,我想测试一些东西,所以我希望你能帮助我。

1 个答案:

答案 0 :(得分:2)

我认为这是纯粹的C代码。你应该写一些类似的东西:

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

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