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 4 of 4

Thread: java.lang.UnsatisfiedLinkError

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.lang.UnsatisfiedLinkError

    Hello,

    I am getting the following error. Please advide where I may be going wrong.

    Exception in thread "main" java.lang.UnsatisfiedLinkError: Plcio.open(Ljava/lang/StringI
    at Plcio.open(Native Method)
    at Plcio.main(Plcio.java:11)


    Plcio.java

    public class Plcio {
    	private native int open(String plcName);
    	static {
    		//System.loadLibrary("test");
    		System.load("/home/usr/plcioExampleslib/libtest.so");
    	}
     
     
    	public static void main(String[] args) {
    		Plcio plcio = new Plcio();
    		int result = plcio.open("virtual");
    		System.out.println("result = " + result);
    	}
    }


    Plc.h

    #ifndef _PLC_H
    #define _PLC_H
     
    #include<iostream>
    #include<string>
    #include<vector>
    #include<plc.h>
    #include<jni.h>
     
    typedef PLC* plcPointer;
     
    class Plc{
     
    public:
    	Plc() { }
    	Plc(const std::string &plctype, const std::vector<int> &data):_plctype(plctype),_data(data) {}
     
    	JNIEXPORT jint JNICALL Java_Plcio_open (JNIEnv *env, jobject jobj, jstring name) ;
     
    private:
    	plcPointer _ptr;
    	const std::string _plctype;
    	std::vector<int> _data;
    };
     
     
    #endif



    Plc.cpp

    #include "Plc.h"
    #include <jni.h>
     
    using namespace std;
     
    JNIEXPORT jint JNICALL  Plc::Java_Plcio_open (JNIEnv *env, jobject jobj, jstring name) {
     
      const char *plcname = (env)->GetStringUTFChars(name, 0);
      _ptr = plc_open(const_cast<char*>(plcname));
      env->ReleaseStringUTFChars(name, plcname);
     
      if(_ptr == NULL) {
        plc_print_error(_ptr, "plc_open\n");
        return -1;
      } else 
          cout << " open successfully " << endl; 
      return 0;    
    }



    Regards,

    -H

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java.lang.UnsatisfiedLinkError

    Look at the API for System.load:
    PHP Code:
    Throws:
        
    UnsatisfiedLinkError - if the file does not exist
    Verify the path and file name you are trying to load /home/usr/plcioExampleslib/libtest.so

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.UnsatisfiedLinkError

    Thank you for your reply. I am certain that the path exists and the library is present in the path.

    Regards,

    -H

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: java.lang.UnsatisfiedLinkError

    (env)->GetStringUTFChars(name, 0);

    Becomes

    (env)->GetStringUTFChars(env, name, null);

    Chris

Similar Threads

  1. java.lang.NullPointerException - Help
    By mds1256 in forum Exceptions
    Replies: 5
    Last Post: November 30th, 2009, 06:31 PM
  2. Java.lang.reflect.invocationTargetException
    By varun in forum Exceptions
    Replies: 5
    Last Post: November 3rd, 2009, 10:40 AM
  3. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  4. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java SE API Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 09:42 AM
  5. [SOLVED] Facing java error "cannot be applied to (java.lang.String)"
    By tazjaime in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2009, 10:19 AM