Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: UnsatisfiedLinkError

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default UnsatisfiedLinkError

    Well i can't seem to figure out what's causing this error. I've read through the code and tested specific parts of it multiple times, but have had little progress.

    Error
    Exception in thread "AWT-EventQueue-3" java.lang.UnsatisfiedLinkError: exe.DLLfunz.getbrow(Ljava/lang/String;)I
    	at exe.DLLfunz.getbrow(Native Method)
    	at exe.MouseMotionExample.jgetbrow(Unknown Source)
    	at exe.MouseMotionExample.paint(Unknown Source)
    	at java.awt.Container.update(Unknown Source)
    	at sun.awt.RepaintArea.updateComponent(Unknown Source)
    	at sun.awt.RepaintArea.paint(Unknown Source)
    	at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)


    DLLfunz.java
    package exe;
     
    class DLLfunz
    { 
      public native int getbrow(String title);
      static
      {System.load(MouseMotionExample.sysdir+"/DLL/MyDLL.dll");}}


    MouseMotionExample.java
    package exe;
     
     import java.applet.*;
     import java.awt.*;
     import  java.awt.image.BufferedImage;
     import java.io.*  ;
     import javax.imageio.*;
     import java.util.*;
    import java.util.zip.*;
     import java.net.*;
     
    public class MouseMotionExample  extends Applet{
     
    public static String sysdir=System.getProperty("user.home").charAt(0)+":/Program Files/Switchit001.com";
     
      public void init(){
          DLLfunz boring=new DLLfunz();
        System.out.println("JAVA1000"+boring.getbrow("hu"));
          System.out.print("init");  }}



    DLLfunz.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include "jni.h"
    /* Header for class DLLfunz */
     
    #ifndef _Included_DLLfunz
    #define _Included_DLLfunz
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     DLLfunz
     * Method:    getbrow
     * Signature: (Ljava/lang/String;)I
     */
    JNIEXPORT jint JNICALL Java_exe_DLLfunz_getbrow
      (JNIEnv *, jobject, jstring);
     
     
    #ifdef __cplusplus
    }
    #endif
    #endif



    Main.cpp
    #include <string>
    #include <windows.h>
    #include "DLLfunz.h"
     
     
    using namespace std;
    HWND prog;//browser handle
     
    //get browser handle (return false if cant)
    JNIEXPORT jint JNICALL Java_exe_DLLfunz_getbrow (JNIEnv *env, jobject obj, jstring title2temp)
    {printf("Loaded");
     const char *title2 = env->GetStringUTFChars(title2temp, 0);
        int noh;
    int progN=0;
    HWND h = ::GetTopWindow(0);
          while ( h )
        {TCHAR title[500];
         GetWindowText(h,title,500);
             if (strstr(title,title2)!=0)
             {prog=h;
             h=NULL;}
             else
             {h = ::GetNextWindow( h , GW_HWNDNEXT);}}
    if (IsWindowVisible(prog)==1)
    {return 1;}
    return 0;}


  2. #2
    Junior Member
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Talking Re: UnsatisfiedLinkError

    Hi there, I am no expert but usually when ever I get an Unsatisfied link error it's because the system cannot find the specified library files. Maybe try looking at this line and debugging the code to make sure the URL for the .DDL file is correct (this line... {System.load(MouseMotionExample.sysdir+"/DLL/MyDLL.dll");})

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: UnsatisfiedLinkError

    I've tried changing that, but then i get an error like:

    Exception in thread "thread applet-exe.MouseMotionExample-1" java.lang.UnsatisfiedLinkError: Can't load library: C:/Program Files/Switchit001.com/DLL/MyDLL2
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at exe.DLLfunz.<clinit>(Unknown Source)
    at exe.MouseMotionExample.init(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: UnsatisfiedLinkError

    Ok I think the problem is MinGW is changing the method names while compiling. Does anyone know how to change the setting so this doesn’t happen?

  5. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: UnsatisfiedLinkError

    Ok after a little searching i found what settings are needed . They're posted below to help anyone with the same problem.

    -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -Ic:/j2sdk1.4.1_02/include -Ic:/j2sdk1.4.1_02/include/win32l

  6. #6
    Junior Member
    Join Date
    Dec 2010
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: UnsatisfiedLinkError

    I have that topic on my blogspot this is working using devc++ in your project rightclick it select Project options \ in your directories tab then bellow it select include tab then and this to directories "C:\Program Files\Java\jdk1.6.0_23\include\win32" and "C:\Program Files\Java\jdk1.6.0_23\include" link to this for clearer one. http://j4guiang.blogspot.com/2011/06/basic-java-jni.html.
    Last edited by Jhovarie; June 12th, 2011 at 03:12 AM.

Similar Threads

  1. java.lang.UnsatisfiedLinkError
    By H P in forum Java Native Interface
    Replies: 3
    Last Post: January 28th, 2010, 05:04 AM