请教关于JNI的问题! 你用的不是静态方法,看看你的java代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你是说调用topsideTesttools方法的方法应该是静态方法? 加了static修饰符,还是一样的错误啊 //Jrunc.javapackage jnijc;public class Jrunc{ public Jrunc() { } public native static String helloWorld(); public native static int sum(int a,int b);}//Test.javapackage jnijc;public class Test{ public Test() { } public static void main(String[] args) { Test test1 = new Test(); try { System.loadLibrary("jnijc_Jrunc") ; Jrunc jc=new Jrunc(); System.out .println(jc.helloWorld() ) ; System.out .println(jc.sum(1,2) ); } catch(Exception ex) { ex.printStackTrace() ; } }}//jnijc_Jrunc.h/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class jnijc_Jrunc */#ifndef _Included_jnijc_Jrunc#define _Included_jnijc_Jrunc#ifdef __cplusplusextern "C" {#endif/* * Class: jnijc_Jrunc * Method: helloWorld * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_jnijc_Jrunc_helloWorld (JNIEnv *, jclass);/* * Class: jnijc_Jrunc * Method: sum * Signature: (II)I */JNIEXPORT jint JNICALL Java_jnijc_Jrunc_sum (JNIEnv *, jclass, jint, jint);#ifdef __cplusplus}#endif#endif//jnijc_Jrunc.cpp#include "jnijc_Jrunc.h"/* * Class: jnijc_Jrunc * Method: helloWorld * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_jnijc_Jrunc_helloWorld (JNIEnv *env, jclass jc){ char hello[]="hello world!"; jstring a=env->NewStringUTF(hello); return a;}/* * Class: jnijc_Jrunc * Method: sum * Signature: (II)I */JNIEXPORT jint JNICALL Java_jnijc_Jrunc_sum (JNIEnv *env, jclass jc, jint jia, jint jib){ jint sum=jia+jib; return sum;}int main(){ return 0;} 你的意思是native方法必须是静态的?但是java tutorial里面不是啊另外,只能在main方法里调用吗?其它方法不行? 我改为下面这样可还是一样的错误啊public native static void topsideTesttools();...public static void callback() throws Exception{System.loadLibrary("topside");new TestToolsBootstrap().topsideTesttools();...} 已经搞定了,native方法不需要是静态的,问题出在我的java程序是在包里的,在c程序中函数名里面没有包含包。 从java字符串扣留机制看字符串常量与变量的区别 jsp查询数据和库里不同步 如何绘制斜的矩形 jmf制作播放器怎样实现多种音频的播放 linux 下 java的 mysql 驱动问题? 请教List用法 初学者的小问题,帮帮忙阿 请教:学JAVA,看那本书比较好一点(对于低,中,高级人员)? 请问"这个符号在JAVA中应怎么表示呢?谢谢 java 线程问题 谁有“JAVA无难事(视频教学,12CD-ROM)”的光盘啊? 各位,问个log4j的问题。
package jnijc;public class Jrunc
{
public Jrunc()
{
}
public native static String helloWorld();
public native static int sum(int a,int b);}
//Test.java
package jnijc;public class Test
{
public Test()
{
} public static void main(String[] args)
{
Test test1 = new Test();
try
{
System.loadLibrary("jnijc_Jrunc") ;
Jrunc jc=new Jrunc();
System.out .println(jc.helloWorld() ) ;
System.out .println(jc.sum(1,2) );
}
catch(Exception ex)
{
ex.printStackTrace() ;
}
}}
//jnijc_Jrunc.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jnijc_Jrunc */#ifndef _Included_jnijc_Jrunc
#define _Included_jnijc_Jrunc
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: jnijc_Jrunc
* Method: helloWorld
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_jnijc_Jrunc_helloWorld
(JNIEnv *, jclass);/*
* Class: jnijc_Jrunc
* Method: sum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_jnijc_Jrunc_sum
(JNIEnv *, jclass, jint, jint);#ifdef __cplusplus
}
#endif
#endif
//jnijc_Jrunc.cpp
#include "jnijc_Jrunc.h"
/*
* Class: jnijc_Jrunc
* Method: helloWorld
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_jnijc_Jrunc_helloWorld
(JNIEnv *env, jclass jc)
{
char hello[]="hello world!";
jstring a=env->NewStringUTF(hello);
return a;
}/*
* Class: jnijc_Jrunc
* Method: sum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_jnijc_Jrunc_sum
(JNIEnv *env, jclass jc, jint jia, jint jib)
{
jint sum=jia+jib;
return sum;
}
int main()
{
return 0;
}
另外,只能在main方法里调用吗?其它方法不行?
public native static void topsideTesttools();
...
public static void callback() throws Exception{
System.loadLibrary("topside");
new TestToolsBootstrap().topsideTesttools();
...
}