本人是一位小C程序员,最近工作需要,要调在c中用一些java程序(linux),使用JNI(网上查到的)调用比如:java某一个类中有一个函数:public void put(short c, int address){
p[address]=(char) c;
}那么,我在c程序中应如何调用?我是这么调用的:
JNIEXPORT void JNICALL Java_JniTest_getLicence(JNIEnv *pEnv,
jobject test,
jobject obj)
{
........
jmethodID mid = NULL;
jclass cls = (*pEnv)->GetObjectClass(pEnv, obj);
mid =(*pEnv)->GetMethodID(pEnv, cls,"put","(S,I)V");
(*pEnv)->CallVoidMethod(pEnv, obj,mid,(jshort)MemoBuffer[j],j);
}
程序报错,但是如果是调用一个参数的接口是没问题的:
jmethodID mid = NULL;
jclass cls = (*pEnv)->GetObjectClass(pEnv,obj);
mid = (*pEnv)->GetMethodID(pEnv,cls,"setId","(J)V");
(*pEnv)->CallVoidMethod(pEnv,obj,mid,(jlong)m_IDNum);
return m_IDNum;java接口是别的组开发的,不能修改,我知道这个问题对于各位java的大侠们说应该很菜,可实在是不懂java,惭愧!!
顺便问问,如果接口函数中参数是一个类的话,我该怎么调用,如果是好几个呢?
(分数不多了!!)
解决方案 »
- 今年7月差不多开始实习,我现在java只知道基础语法,如何才能提升
- Android 小问题
- socket客户端如何等到服务端接受处理完成并返回处理结果后再往下进行(同步问题)
- InputStream的read方法的问题
- JFrame 和JDialog都继承在window,那么JDialog 是怎样去掉最大化和最小化的呢?
- 用java如何实现gb2312和utf-8之间的转换
- 急!TreeSet比较问题!
- 求助,请帮我看看哪出了问题
- 如何在winme下使用j2sdk1.3?
- driver = (Driver)Class.forName(driverName).newInstance()和Class.forName(driverName);有什么不同呀?
- 关于键盘输入存入String数组问题
- io问题。来人哦
mid =(*pEnv)->GetMethodID(pEnv, cls,"put","(SI)V"); Method descriptors are formed by placing the field descriptors of all argument types in a pair of parentheses, and following that by the field descriptor of the return type. There are no spaces or other separator characters between the argument types. "V" is used to denote the void method return type. Constructors use "V" as their return type, and use "<init>" as their name.Here are some examples of JNI method descriptors and their corresponding method and constructor types.Method Descriptor
Java Language Type
"()Ljava/lang/String;"
String f();
"(ILjava/lang/Class;)J"
long f(int i, Class c);
"([B)V"
String(byte[] bytes);
是函数的描述错了。原来可以通过javap 这个命令可以查看某个函数的描述。
结贴了!!