Results 1 to 3 of 3
  1. #1
    JNB
    JNB is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default UnsatisfiedLinkError using JNI

    Hi,

    I have created a simple JNI Java and c++ classes. The code looks as below. I was able to compile the code without errors. But when I'm trying to run the java class I get the UnsatisfiedLinkError error. I have the necessary dll file in the same location as the Java class file. Please help

    Error:
    C:\foo>java JNIFoo
    Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\foo\foo.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.jav a:1807)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1732)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at JNIFoo.<clinit>(JNIFoo.java:5)
    Could not find the main class: JNIFoo. Program will exit.

    Even java -Djava.library.path=C:\foo JNIFoo doesnt help

    Java class:
    public class JNIFoo {
    public native String nativeFoo();

    static {
    System.loadLibrary("foo");
    }

    public void print () {
    String str = nativeFoo();
    System.out.println(str);
    }

    public static void main(String[] args) {
    (new JNIFoo()).print();
    return;
    }
    }

    C++ class: (Compiled in Visual Studio 2008)

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "jni.h"
    #include "JNIFoo.h"

    JNIEXPORT jstring JNICALL Java_JNIFoo_nativeFoo (JNIEnv *env, jobject obj)
    {
    jstring ret = 0;

    char *buf = (char*)malloc(10);
    strcpy(buf, "From Native");
    jstring jstrBuf = env->NewStringUTF(buf);

    return jstrBuf;

    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Double posted. Reply to advanced Java.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

Similar Threads

  1. UnsatisfiedLinkError on dll load
    By Bharath_M in forum Advanced Java
    Replies: 8
    Last Post: 04-11-2011, 11:23 AM
  2. UnsatisfiedLinkError
    By leepan2008 in forum Advanced Java
    Replies: 4
    Last Post: 01-07-2011, 04:40 AM
  3. JNI: ava.lang.UnsatisfiedLinkError
    By tecno40 in forum Java Applets
    Replies: 0
    Last Post: 11-19-2010, 11:59 PM
  4. UnsatisfiedLinkError
    By Hussain Ali in forum Eclipse
    Replies: 2
    Last Post: 04-11-2010, 07:59 AM
  5. Replies: 0
    Last Post: 08-12-2007, 03:23 PM

Posting Permissions

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