1

I am getting java.lang.UnsatisfiedLinkError when I pass a integer to the method call. If I don't pass any parameter , the function works like a charm. What am I possibly doing wrong ?

Exception in thread "main" java.lang.UnsatisfiedLinkError: JniTimer.jniWait(I)V at JniTimer.main(JniTimer.java:15)

Java Code:

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 header:

   /* 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 implementation:

    #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);
        }
    }
Ahmet Kakıcı
  • 6,294
  • 4
  • 37
  • 49
user1805280
  • 251
  • 1
  • 5
  • 14
  • 1
    are you sure you're using right version of your dll? just in case :) – Denis Tulskiy Nov 09 '12 at 09:22
  • yes, I have also tried making the change to load library from explicit path System.load("C:/JniTimer.dll"); – user1805280 Nov 09 '12 at 15:56
  • well, to play safe, try to dig up which methods end up in your dll. howto here: http://stackoverflow.com/questions/437432/is-there-a-way-to-find-all-the-functions-exposed-by-a-dll – Denis Tulskiy Nov 09 '12 at 16:11
  • Thanks Denis. That was it. THe dll has incorrect method definition. I cleaned up the project and it went thru. I have another issue now. The jar/dll combination works fine on one machine (Machine1) but not on another (Machine). I have copied dll in C:\ which is where I load the dll from. Getting UnsatidiedLinkError on Machine2. – user1805280 Nov 09 '12 at 18:34
  • Got it working. Visual Studio redistributable was needed. – user1805280 Nov 10 '12 at 05:01

0 Answers0