Problem regarding JNI impelmentation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem regarding JNI impelmentation

  1. #1
    Kundan Vyas Guest

    Problem regarding JNI impelmentation


    Hi,
    I ve jus started working on JNI.I am facing a problem.After following
    all the steps which are being mentioned in the JNI docs I am getting the
    following error.
    Exception in thread "main" java.lang.UnsatisfiedLinkError:Add
    at HelloWorld.Add(Native Method)
    at HelloWorld.main(HelloWorld.java:18)

    Steps I followed

    Step 1) Write HelloWorld.java



    class HelloWorld {
    public native int Add(int x,int y);
    static
    {
    try{
    System.loadLibrary("intAdd");
    }
    finally
    {
    System.out.println("arg debug: after loadLibrary");
    }
    }

    public static void main(String[] args) {
    HelloWorld obj=new HelloWorld();
    int val=obj.Add(10,20);
    }
    }

    Step 2)javac HelloWorld.java

    Step 3)Create a intAdd.dll with the native implementation of method
    Add(int,int) in VC++.

    Step 4)Register the dll using the following command
    regsvr32 "d:\staff\kundan\workdir\jni\intAdd.dll" .
    The .dll file is on the CLASSPATH also.

    Step 5)javah -jni HelloWorld

    Step 6)java HelloWorld

    And I am getting this error.

    Are these steps complete or am I missing something????
    Kindly send me a solution for this.

    Kundan Vyas
    kundan@ionideainteractive.com




  2. #2
    Kent Guest

    Re: Problem regarding JNI impelmentation


    Hi Kundan,

    This error means that the JRE cannot find the implementation of the native
    method.

    To ensure that the dll is visible to the Java app, put it in the same directory
    as where you're running the app from. There is no need to register it then.
    This is the most likely cause as the loadLibrary method throws the UnsatisfiedLinkError
    if the system cannot find the dll.

    Also, did you use javah to create the header file for the dll? If not, it
    may have an incorrect function name. It should be something like com_package_Add(...).

    Regards,
    Kent



    "Kundan Vyas" <kundan@ionideainteractive.com> wrote:
    >
    >Hi,
    > I ve jus started working on JNI.I am facing a problem.After following
    >all the steps which are being mentioned in the JNI docs I am getting the
    >following error.
    >Exception in thread "main" java.lang.UnsatisfiedLinkError:Add
    >at HelloWorld.Add(Native Method)
    >at HelloWorld.main(HelloWorld.java:18)
    >
    >Steps I followed
    >
    >Step 1) Write HelloWorld.java
    >
    >
    >
    > class HelloWorld {
    > public native int Add(int x,int y);
    > static
    > {
    > try{
    > System.loadLibrary("intAdd");
    > }
    > finally
    > {
    > System.out.println("arg debug: after loadLibrary");
    > }
    > }
    >
    > public static void main(String[] args) {
    > HelloWorld obj=new HelloWorld();
    > int val=obj.Add(10,20);
    > }
    >}
    >
    >Step 2)javac HelloWorld.java
    >
    >Step 3)Create a intAdd.dll with the native implementation of method
    >Add(int,int) in VC++.
    >
    >Step 4)Register the dll using the following command
    >regsvr32 "d:\staff\kundan\workdir\jni\intAdd.dll" .
    >The .dll file is on the CLASSPATH also.
    >
    >Step 5)javah -jni HelloWorld
    >
    >Step 6)java HelloWorld
    >
    >And I am getting this error.
    >
    >Are these steps complete or am I missing something????
    >Kindly send me a solution for this.
    >
    >Kundan Vyas
    >kundan@ionideainteractive.com
    >
    >
    >



  3. #3
    Ruchi Dhar Guest

    Re: Problem regarding JNI impelmentation


    >Step 3)Create a intAdd.dll with the native implementation of method
    >Add(int,int) in VC++.
    >
    >Step 4)Register the dll using the following command
    >regsvr32 "d:\staff\kundan\workdir\jni\intAdd.dll" .
    >The .dll file is on the CLASSPATH also.
    >


    There is no need to register the dll with regserv32. The dll you need to
    develop is simple win32dll with plain object code. Once you create the dll
    keep the dll in path not in classpath. All dlls are loaded from PATH.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center