Results 1 to 8 of 8

Thread: Java JNI

  1. #1
    nishabinu is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Post Java JNI

    I have a problem creating a simple Java Application that uses JNI to load a dll that prints the mesage “Passing string from Java”.
    i have wriiten a simple code :

    public class TESTJNI
    {


    static
    {
    System.load("jnitest");
    }


    native void showMessage( String str);
    public TESTJNI()
    {
    System.out.println( "In the constructor of the java program" );

    }


    public static void main( String s[] )
    {
    TESTJNI JNT = new TESTJNI();
    JNT.showMessage("Passing string from Java");
    }
    }
    EXCEPTION GENERATED
    Exception in thread "main" java.lang.UnsatisfiedLinkError

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Where is the library stored?
    According to the API specs of load, "The filename argument must be a complete path name"

  3. #3
    nishabinu is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    I tried with complete pathname, still that error occured......

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You should use System.loadLibrary

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Here is an example that you should read: Chapter 5 Continued: JNI Example

  6. #6
    nishabinu is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    When i tried with complete pathname where dll load... System.loadLibrary("D:\\JNITEST\\JNITEST\\src\\jni test\\jnitest.dll");
    the error is "Could not find the main class.Programm will exit ".
    also tried with System.loadLibrary("jnitest");
    Exception in thread "main" java.lang.UnsatisfiedLinkError (same error).

  7. #7
    nishabinu is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    k i will try....thanks.....

  8. #8
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default

    if you are using complete path use this

    System.load("D:\\JNITEST\\JNITEST\\src\\jni test\\jnitest.dll");

    also
    try this blog for basic java jni Basic Java JNI | j4guiang.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •