java.lang.UnsatisfiedLinkError
当我将整数传递给方法调用时,我得到了。如果我不传递任何参数,该函数就像一个魅力。我可能做错了什么?
线程“main”中的异常 java.lang.UnsatisfiedLinkError: JniTimer.jniWait(I)V at JniTimer.main(JniTimer.java:15)
Java 代码:
public class JniTimer {
static {
System.loadLibrary("JniTimer.dll");
}
public native void jniWait(int msec);
public static void main(String[] args) {
JniTimer myTimer = new JniTimer();
int a = 100;
myTimer.jniWait(a);
}
}
JNI 标头:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JniTimer */
#ifndef _Included_JniTimer
#define _Included_JniTimer
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JniTimer
* Method: jniWait
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_JniTimer_jniWait (JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
JNI 实现:
#include "stdafx.h"
#include<jni.h>
#include<windows.h>
#include "JniTimer.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_JniTimer_jniWait(JNIEnv *env, jobject obj , jint ji ) {
printf("Entered C methos") ; //////JUST PRINTING FOR DEBUG
HANDLE hWaitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hWaitEvent) {
printf ("Inside wait");
WaitForSingleObject(hWaitEvent,ji);
CloseHandle (hWaitEvent);
}
}