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

[Q] native methods (C)

0 views
Skip to first unread message

Shouyi Hsiao

unread,
Oct 7, 1996, 3:00:00 AM10/7/96
to

Hi,

I am just trying to get the simple HelloWorld example for implementing
native methods in Java to work. I basically just have a native method in
a Java class "Hello" that is implemented in C and prints "Hello World". I've
successfully compiled a shared library from my *.c files, but when I
tried to run the Java main program, it gives me the following message:

% java Main
java.lang.NullPointerException
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at Hello.<clinit>(Hello.java:9)
at java.lang.Compiler.<clinit>(Compiler.java)
java.lang.UnsatisfiedLinkError: displayHelloWorld
at Main.main(Main.java:4)

*********************************************************

I then tried to figure out what's going on by running jdb:

% jdb Main
Initializing jdb...
java.lang.NoClassDefFoundError: java/lang/UNIXProcess
at java.lang.Runtime.exec(Runtime.java)
at java.lang.Runtime.exec(Runtime.java)
at sun.tools.debug.RemoteAgent.<init>(RemoteAgent.java:96)
at sun.tools.debug.RemoteDebugger.<init>(RemoteDebugger.java:69)
at sun.tools.ttydebug.TTY.<init>(TTY.java:1271)
at sun.tools.ttydebug.TTY.main(TTY.java:1395)

***************************************************************

I looked into that *.class files supplied with our version of JDK
(version 1.0, I think) but couldn't find any file named
"UNIXProcess.class".

Does anyone know what the problem is and/or suggest a quick fix?

Thanks a bunch,

-Shouyi Hsiao
sho...@cory.eecs.berkeley.edu


Tim Diekmann

unread,
Oct 7, 1996, 3:00:00 AM10/7/96
to

Hi there,

Shouyi Hsiao wrote:
>
> Hi,
>
> I am just trying to get the simple HelloWorld example for implementing
> native methods in Java to work. I basically just have a native method in
> a Java class "Hello" that is implemented in C and prints "Hello World". I've
> successfully compiled a shared library from my *.c files, but when I
> tried to run the Java main program, it gives me the following message:
>
> % java Main
> java.lang.NullPointerException
> at java.lang.Runtime.loadLibrary(Runtime.java)
> at java.lang.System.loadLibrary(System.java)
> at Hello.<clinit>(Hello.java:9)
> at java.lang.Compiler.<clinit>(Compiler.java)
> java.lang.UnsatisfiedLinkError: displayHelloWorld

> at Main.main(Main.java:4)
>
I had almost the same problem, but finally fixed it :-)
First, follow the steps in the Java Tutorial at java.sun.com.
Then there are two ways of loading the runtime library in
java.
The first is using System.load(<filename>)
where <filename> is the name of the library with the absolute
path,e.g. /home/users/whatever/classes/mylib

The second is to rename your library to lib<mylibraryname>.so
and add your library directory to LD_LIBRARY_PATH with setenv.
This was what helped me out. Trial and error ...

ciao,____
|im Diekmann
diek...@rhrk.uni-kl.de

0 new messages