hajava
asked on
java.lang.UnsatisfiedLinkError
I use a wrapper class HiResTimer (JavaPro Aug.01 p67) which loads a DLL hirestimer.dll in the same directory ( System.loadLibrary("hirest imer");). Everything worked fine. But when I added a package definition to specify a package name, the DLL was loaded, the wrapper class instantated, but on the first call of a method I get a "java.lang.UnsatisfiedLink Error: isHighResTimerAvailable". What's the problem?
Which directory is your library in?
ASKER
The library is in directory H:\java\ch\abegglen\nativ. The class is in the same directory. Classpath is H:\java. The intended package name was ch.abegglen.nativ.
Try putting the lib in h:\java or somewhere in your PATH.
> "java.lang.UnsatisfiedLink Error: isHighResTimerAvailable"
it seems that you have changed 'package' statement for some class that contains native methods. since .dll entry for each native method contains full class/package/parameter signatures, when you chnage the package, JavaVM won't be able to find the native method in the .dll.
check the JNI tutorial at www.javasoft.com
it seems that you have changed 'package' statement for some class that contains native methods. since .dll entry for each native method contains full class/package/parameter signatures, when you chnage the package, JavaVM won't be able to find the native method in the .dll.
check the JNI tutorial at www.javasoft.com
ASKER
heyhey wrote: "since .dll entry for each native method contains full class/package/parameter signatures"
How do I add <package name> to the signature?
In the tutorial I find only one sentence about packages:
"The name of the native language function that implements the native method consists of the prefix Java_, the package name, the class name, and the name of the native method. Between each name component is an underscore "_" separator."
The JNI Spec has an example for a package:
Java_pkg_Cls_f_ILjava_lang _String_2
//where pkg is the package name
But I tried
//hirestimer.cpp
JNIEXPORT jboolean JNICALL Java_ch_abegglen_nativ_HiR esTimer_is HighResTim erAvailabl e
(JNIEnv *, jobject)
//where ch.abegglen.nativ is the package name
does not have the desired effect. I still have a java.lang.UnsatisfiedLinkE rror: isHighResTimerAvailable. And this is *after* the library has been loaded from C:\WINDOWS which is in my PATH.
How do I add <package name> to the signature?
In the tutorial I find only one sentence about packages:
"The name of the native language function that implements the native method consists of the prefix Java_, the package name, the class name, and the name of the native method. Between each name component is an underscore "_" separator."
The JNI Spec has an example for a package:
Java_pkg_Cls_f_ILjava_lang
//where pkg is the package name
But I tried
//hirestimer.cpp
JNIEXPORT jboolean JNICALL Java_ch_abegglen_nativ_HiR
(JNIEnv *, jobject)
//where ch.abegglen.nativ is the package name
does not have the desired effect. I still have a java.lang.UnsatisfiedLinkE
ASKER
I found the solution, thanks anyway.
I changed the C++ code like this
JNIEXPORT jboolean JNICALL Java_ch_abegglen_nativ_HiR esTimer_is HighResTim erAvailabl e
(JNIEnv *, jobject)
where ch.abegglen.nativ is the package name. Then I called javah with parameter -classpath %cp% ch.abegglen.nativ.HiResTim er. The resulting HiResTimer.h allowed to compile a usable DLL then.
The DLL can reside in the package directory, not as you suggested.
Thanks.
I changed the C++ code like this
JNIEXPORT jboolean JNICALL Java_ch_abegglen_nativ_HiR
(JNIEnv *, jobject)
where ch.abegglen.nativ is the package name. Then I called javah with parameter -classpath %cp% ch.abegglen.nativ.HiResTim
The DLL can reside in the package directory, not as you suggested.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- Points for heyhey_
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venabili
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
- Points for heyhey_
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venabili
EE Cleanup Volunteer