JNI question. UnsatisfiedLinkError upon method invocation

Discussion in 'Java' started by CliffMacGillivray, Sep 15, 2005.

  1. I am getting an UnsatisfiedLinkError not when I load the library but
    rather when I call a native method whose implementation is inside
    the dll.
    Some code:
    package myPackage;

    public class Main{

    public static void main(String[] args){
    System.load("C:development\\myNative.dll");
    someObject j=new someObject();
    j.someNativeMethod();
    }
    }

    The exception is thrown not on the load but on the method invocation
    j.someNativeMethod();

    The someObject class is really basic

    public class someObject{

    public someObject(){
    //nothing here yet
    }

    public native void someNativeMethod();

    public void aJavaMethod(){
    someNativeMethod();
    }

    }

    Any advice on what could be causing this? I am sure that the native
    method is appropriately defined and all that. I have used a tool
    to dump out the symbols form the dll and I am sure everything is there.

    Oh, and no, these are not the real class and method names. My employer
    is really fanatical about any sort of public code release so I
    anonymized the source a little to avoid trouble.
     
    CliffMacGillivray, Sep 15, 2005
    #1
    1. Advertising

  2. ok, a quick followup. This works if I don't specify a package!?!?
     
    CliffMacGillivray, Sep 15, 2005
    #2
    1. Advertising

  3. CliffMacGillivray

    Pete Barrett Guest

    On Thu, 15 Sep 2005 12:52:14 -0400, CliffMacGillivray
    <> wrote:

    >I am getting an UnsatisfiedLinkError not when I load the library but
    >rather when I call a native method whose implementation is inside
    >the dll.
    >....
    >Any advice on what could be causing this? I am sure that the native
    >method is appropriately defined and all that. I have used a tool
    >to dump out the symbols form the dll and I am sure everything is there.
    >

    At a guess, the native method in the native DLL requires another DLL
    which it can't find.



    Pete Barrett
     
    Pete Barrett, Sep 15, 2005
    #3
  4. On Thu, 15 Sep 2005 13:14:42 -0400, CliffMacGillivray wrote:
    > ok, a quick followup. This works if I don't specify a package!?!?


    Then you either didn't specify the _fully_qualified_ classname when
    you ran javah, or you didn't use the symbol names in the header file
    it generated. They will be different when a package is used.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Sep 15, 2005
    #4
  5. Gordon Beaton wrote:
    > On Thu, 15 Sep 2005 13:14:42 -0400, CliffMacGillivray wrote:
    >
    >>ok, a quick followup. This works if I don't specify a package!?!?

    >
    >
    > Then you either didn't specify the _fully_qualified_ classname when
    > you ran javah, or you didn't use the symbol names in the header file
    > it generated. They will be different when a package is used.
    >
    > /gordon

    D'oh!!
    You are right. Also, another respondent was also correct in
    that I had another dependent .dll which I needed to load. 2 problems I had.
    Thanks for all the help. c.l.j.p rawks! :)
     
    CliffMacGillivray, Sep 15, 2005
    #5
  6. CliffMacGillivray

    Roedy Green Guest

    On Thu, 15 Sep 2005 12:52:14 -0400, CliffMacGillivray
    <> wrote or quoted :

    > System.load("C:development\\myNative.dll");


    That code depends on the current directory.

    Try System.load("C:\\development\\myNative.dll");

    The proper way to do this which will allow other platform
    implementations is to do

    Try System.loadLibrary("myNative");

    and install your library on the java.library.path (see
    http://mindprod.com/wassup.html to discover the system property)

    For general help with UnsatisfiedLinkError see

    http://mindprod.com/jgloss/runerrormessages.html#UNSATISFIEDLINKERROR
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 15, 2005
    #6
  7. CliffMacGillivray

    Roedy Green Guest

    On Thu, 15 Sep 2005 12:52:14 -0400, CliffMacGillivray
    <> wrote or quoted :

    >My employer
    >is really fanatical about any sort of public code release so I
    >anonymized the source a little to avoid trouble.


    The problem is so often the cause is a tiny spelling or capitalization
    error.

    You might want to create a SCCSSE. If it works and your real one does
    not, you can check for just where the extract differs in form.


    Pay special attention to package names.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 15, 2005
    #7
  8. CliffMacGillivray

    Roedy Green Guest

    On Thu, 15 Sep 2005 13:14:42 -0400, CliffMacGillivray
    <> wrote or quoted :

    >ok, a quick followup. This works if I don't specify a package!?!?


    read the notes in http://mindprod.com/jgloss/jni.html


    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 15, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sharad nangia

    Answer to UnsatisfiedLinkError - JNI

    sharad nangia, Sep 2, 2003, in forum: Java
    Replies:
    0
    Views:
    3,040
    sharad nangia
    Sep 2, 2003
  2. Frank

    JNI UnsatisfiedLinkError

    Frank, Oct 15, 2003, in forum: Java
    Replies:
    5
    Views:
    6,000
    Gordon Beaton
    Oct 16, 2003
  3. david
    Replies:
    2
    Views:
    1,169
    david
    Nov 12, 2003
  4. Chandrashekar
    Replies:
    0
    Views:
    982
    Chandrashekar
    Dec 30, 2003
  5. Daniel Fetchinson
    Replies:
    0
    Views:
    240
    Daniel Fetchinson
    Jun 25, 2008
Loading...

Share This Page