Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java API
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other JSE/JEE APIs
java.lang.UnsatisfiedLinkError
H Padia
Greenhorn
Posts: 8
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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/String;)I
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
Rob Spoor
Sheriff
Posts: 22783
131
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Since when do native methods go into C++ classes? Try extracting it from the class.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to solve UnsatisfiedLinkError? - URGENT...please help
JNI Help
unable to compile (calling C function from Java code)
convert jbyteArray into jString ?
jni methos in c++ class
More...