aspose file tools*
The moose likes Java in General and the fly likes JNI Program RunTime Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JNI Program RunTime Exceptions" Watch "JNI Program RunTime Exceptions" New topic
Author

JNI Program RunTime Exceptions

Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Hai friends
I am trying to call the Functionality from C program to Java Program using JNI
The C program is like
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}

Java Program is
class HelloWorld
{
public native void displayHelloWorld();

static
{
System.loadLibrary("hello");
}
public static void main(String[] args)
{
new HelloWorld().displayHelloWorld();
}
}
I compiled java program using this
javac HelloWorld.java
and i made it as .h file using
javah -jni HelloWorld
Everything is fine but when i am trying to run the java program like this
java HelloWorld
It is saying exception
Exception is
java.lang.UnsatisfiedLinkError: no hello in shared library path
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at
at java.lang.Thread.init(Thread.java)

What shall i do to get the output
Please give me some suggestions
Thanksinadvance
Yours
Rajesh Kumar
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Do you have the line you're using to compile the code? What directory are you putting the .dll/.so file in?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear Michael Ernest
Thankyou VeryMuch
The problem is that what u expressed.
Now I kept .dll file in the directory where class files and .h files stored.
now it is working fine.
Thankyou VeryMuch
Yours
Rajesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JNI Program RunTime Exceptions