Solved

java.lang.UnsatisfiedLinkError

Posted on 2001-09-16
8
459 Views
Last Modified: 2013-11-23
I use a wrapper class HiResTimer (JavaPro Aug.01 p67) which loads a DLL hirestimer.dll in the same directory ( System.loadLibrary("hirestimer");). 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.UnsatisfiedLinkError: isHighResTimerAvailable". What's the problem?
0
Comment
Question by:hajava
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6486270
Which directory is your library in?
0
 

Author Comment

by:hajava
ID: 6486977
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 6486985
Try putting the lib in h:\java or somewhere in your PATH.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 16

Expert Comment

by:heyhey_
ID: 6487038
> "java.lang.UnsatisfiedLinkError: 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
0
 

Author Comment

by:hajava
ID: 6494354
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_HiResTimer_isHighResTimerAvailable
  (JNIEnv *, jobject)
//where ch.abegglen.nativ is the package name
does not have the desired effect. I still have a java.lang.UnsatisfiedLinkError: isHighResTimerAvailable. And this is *after* the library has been loaded from C:\WINDOWS which is in my PATH.

0
 

Author Comment

by:hajava
ID: 6532493
I found the solution, thanks anyway.

I changed the C++ code like this

JNIEXPORT jboolean JNICALL Java_ch_abegglen_nativ_HiResTimer_isHighResTimerAvailable
  (JNIEnv *, jobject)

where ch.abegglen.nativ is the package name. Then I called javah with parameter -classpath %cp% ch.abegglen.nativ.HiResTimer. The resulting HiResTimer.h allowed to compile a usable DLL then.

The DLL can reside in the package directory, not as you suggested.

Thanks.
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 80 total points
ID: 6532542
I changed the C++ code like this
JNIEXPORT jboolean JNICALL Java_ch_abegglen_nativ_HiResTimer_isHighResTimerAvailable


well that was exactly my suggestion - to use correct .dll entry name (that includes all the package/method/parameters info)

sorry for not posting earlier comment - my main workstation was down for 10 days ...
0
 
LVL 20

Expert Comment

by:Venabili
ID: 8916136
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
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 23
servlet example 17 32
Glassfish admin console not working 1 13
Problem to Alipay 10 22
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question