传递int时抛出UnSatisfiedLinkError的jni代码

时间:2012-11-09 07:20:32

标签: java java-native-interface

当我将一个整数传递给方法调用时,我得到java.lang.UnsatisfiedLinkError。如果我没有传递任何参数,该功能就像魅力一样。 我可能做错了什么?

  

线程“main”中的异常java.lang.UnsatisfiedLinkError:   JniTimer.jniWait(I)V           在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);
        }
    }

0 个答案:

没有答案