D:\UNIWORK\PROJECT\NATIVE>java HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: displayHelloWorld
at HelloWorld.displayHelloWorld(Native Method)
at HelloWorld.main(HelloWorld.java:9)
there are no compile errors and the code used (HelloWorld.java and
HelloWorldImp.cpp) is exactly the same as in the tutorial. it seems like it
can't find the c function to use in the dll file. and i beleive that it is
loading the dll file.
i am using jdk1.3, visual c++ 6.0 and win2k.
any ideas? thanks in advance
tim
Correct. If it couldn't find the library, it would have complained with
a different error message.
> i am using jdk1.3, visual c++ 6.0 and win2k.
>
> any ideas? thanks in advance
The usual cause of this problem is that the exported function names in
the DLL don't exactly match what the JVM is looking for, resulting in
the UnsatisfiedLinkError.
First: Check your native code. Then function declaration should look
like this:
JNIEXPORT void JNICALL Java_MyClass_myMethod(JNIEnv *, jobject);
where 'MyClass' and 'myMethod' match your particular Java code.
Second: Make sure you are using the header file created by 'javah', or
at the very least, make sure your functions are wrapped in an extern "C"
block.
Third: Check your compiler options. The compiler may be mangling the
function names. To see if this is the case, use QuickView to look at
the exported function names. They should look exactly as they do in the
function declaration:
Java_MyClass_myMethod
I'm not familiar with the VC++ compiler, so I don't know what options
are required to fix any name mangling problems.
Jim S.
You can also set the library path with the java.library.path properties.
For example:
java -Djava.library.path=C:\\Windows\\ HelloWorld
Bye
Daniel