• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JNI Program RunTime Exceptions

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic