THE FELLOWING IS MY
JAVA PROGRAM:
////////////////////////////////////////////////////////////////////////////
public class JNITest{
/*native methods*/
private native void calculate();
/*the difination of fcn,and the JNI method calculate call it*/
void fcn(int m, int me, int n, float x[], float f,
float g[])
{
float tmp1, tmp2;
tmp1 = x[0] - 2;
tmp2 = x[1] - 1;
f = tmp1 * tmp1 + tmp2 * tmp2;
//if (active[0]),without c.lib,can't be used
g[0] = x[0] - 2 * x[1] + 1;
//if (active[1])
g[1] = -(x[0]*x[0]) / 4 - x[1]*x[1] + 1;
System.out.println("f:"+ f);
System.out.println("g[0]"+g[0]);
System.out.println("g[1]"+g[1]);
return;
}
public static void main(
String []args)
{
JNITest test=new JNITest();
test.calculate();
}
static{
System.loadLibrary("JNITest");
}
}
////////////////////////////////////////////////////////////////////////////
AND THE FELLOWING IS MY PROGRAM WRITTEN WITH VISUAL C++ 6.0
////////////////////////////////////////////////////////////////////////////
#include<jni.h>
#include<stdio.h>
#include"E:\my package\JNITest.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JNITest
* Method: calculate
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_JNITest_calculate
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#define M 2
#define ME 1
#define N 2
JNIEXPORT void JNICALL
Java_JNITest_calculate(JNIEnv *env,jobject obj)
{
/*then access the methods fcn*/
jclass cls=(env)->GetObjectClass(obj);
jmethodID mid=(env)->GetMethodID(cls,"fcn","(III[FF[F

V");
if(mid==NULL){
return;
}
/*translate my own para*/
jfloat x[]={2,2};
jfloat f=0;
jfloat g[2];
/*call the Java fcn*/
printf("In C\n");
(env)->CallVoidMethod(cls,mid,M,ME,N,x,f,g);
}
////////////////////////////////////////////////////////////////////////////
javac JNITest.java :succeed
javah -jni JNITest :succeed
compile the C program into JNITest.dll :succeed
java JNITest :false
the false description:
Exception in
thread "main" java.lang.NoSuchMethodError: fcn
at JNITest.calculate<Native method>
at JNITest.main<JNITest.java:9>
////////////////////////////////////////////////////////////////////////////
WHAT'S WRONG WITH MY PROGRAM?