Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jni error

0 views
Skip to first unread message

Tim

unread,
Jan 28, 2001, 4:35:15 PM1/28/01
to
i am trying to get the simple helloWorld example of JNI working as described
in the java tutorial from sun. but i keep getting the error:

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

Jim Sculley

unread,
Jan 29, 2001, 8:56:22 AM1/29/01
to
Tim wrote:
>
> i am trying to get the simple helloWorld example of JNI working as described
> in the java tutorial from sun. but i keep getting the error:
>
> 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.

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.

Daniel Fischer

unread,
Jan 30, 2001, 8:04:16 AM1/30/01
to

You can also set the library path with the java.library.path properties.

For example:

java -Djava.library.path=C:\\Windows\\ HelloWorld


Bye

Daniel

0 new messages