I am trying to run some program on opencv, but I am getting this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0(Ljava/lang/String;)J
I have already loaded the library, libopencv_java310.so by using this code:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
I have also added the path to the native library.
I have searched a lot on the internet, but the only reason this error comes, is due to native library is not loaded. What could be the other reason of getting this error.
Can anyone help....! Any help will be appreciated.
you might move your System.loadLibrary(Core.NATIVE_LIBRARY_NAME); to a static block so the dll gets loaded before any instruction of opencv .
Related
In my java code, I call System.loadLibrary(A); to load the A.so library. However, my app crashes at run time with this error:
java.lang.UnsatisfiedLinkError: dlopen failed: library "B.so" not found
Admittedly, the B.so library is a dependency of A.so library. But I did not explicitly call System.loadLibrary() on B.so anywhere. I was under the impression that B.so will be covered by A.so. Why is the Java runtime trying to load B.so?
Thanks!
I try to use a word-segmentation software, I create a new java project named JNA, and import the required files into JNA dir, then I try to run it without any code modification, and MyEclipse warns me that:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'E://java//JNI//JnaTest_NLPIR//NLPIR': Native library (win32-x86-64/E://java//JNI//JnaTest_NLPIR//NLPIR.dll) not found in resource path ([file:/D:/javasoft/MyEclipse_workspace/JNA/bin/, file:/D:/javasoft/MyEclipse_workspace/JNA/lib/jna-4.0.0.jar])
I tried to:
create the same dirs and move NLPIR.dll to E:/java/JNI/JnaTest_NLPIR/, it didn't work.
move NLPIR.dll directly to JNA/bin or JNA/lib, but it didn't work, too.
I think that it is caused by the position of my NLPIR.dll. But I could not figure out how to fix it.
I would be grateful for any help or suggestions.
Ensure NLPIR.dll (and all its dependent libraries) is on %PATH%, or use -Djna.library.path=... to indicate the folder it's in.
I seemed to be getting a
JNI- java.lang.UnsatisfiedLinkError: Native error: method not found
when I try to implement libwebp into my project. I followed this link.
and it first gave me an error that it couldn't find the lib "webp". Then I used System.loadLibrary("MYPROJECT"); and it fixed the error, but generated another one saying
Native error: method not found
Every function from libwebp and libwebpJNI are generating the error, so it may have something to do with the native C code.
Any help?
A little background:
I have a java application that needs to talk to a third party hardware on mac. They have given me the sdk but it is not in Java. So I am trying to make jnilib that will act as a bridge between my java application and the SDK.
The issue:
I have made a small sample jnilib that talks to the SDK but when I try to use it in my java program I get the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/john.doe/Desktop/eclipse/workspace/Lesson13_Jni_Smart7/bin/libSmartTest7.jnilib: Library not loaded: build/Release/SMARTResponseSDK.framework/Versions/A/SMARTResponseSDK Referenced from: /Users/john.doe/Desktop/eclipse/workspace/Lesson13_Jni_Smart7/bin/libSmartTest7.jnilib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1742)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at com.learning.lesson13.JniSmart7.<clinit>(JniSmart7.java:6)
From the error it looks like my libSmartTest7.jnilib is looking for the library SMARTResponseSDK.
What I have tried
I know where the library SMARTResponseSDK is on my Mac. I tried copying it over to my working folder in eclipse but I still get the error. I have tried using the -DJava.library.path but I still get the error.
Any ideas on what the best possible approach would be.
Once you are inside JNI code, it no longer matters what java.library.path points at.
Once you are inside JNI code, all you can do is to make sure library is visible to your code via LD_LIBRARY_PATH/DYLD_LIBRARY_PATH, or you can dynamically load your library file from any location you like.
So, for you, I suggest to take a look here:
dynamic loading of library in JNI - http://jnicookbook.owsiak.org/recipe-No-018/
Calling code from shared library (adapter pattern) - http://jnicookbook.owsiak.org/recipe-No-023/
You can also benefit from compilation flags while building your JNI library and use rpath.
When i am trying to run my program it is giving the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob-1.14.3-x86 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:184)
at com.jacob.com.JacobObject.<clinit>(JacobObject.java:108)
at javaSMSTest.main(javaSMSTest.java:18)
please help
From the Javadoc:
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
It is an error related to JNI. loadJacobLibrary is trying to load the native library called jacob-1.14.3-x86 and it is not found on the path defined by java.library.path. This path should be defined as a system property when you start the JVM. e.g.
-Djava.library.path=<dir where jacob library is>
On Windows, the actual native library file will be called jacob-1.14.3-x86.dll while on Linux it would be called libjacob-1.14.3-x86.so
You need the jacob-1.14.3-x86 library on your java library path.
On windows, this would be jacob-1.14.3-x86.dll.
This is a binary file which is used by java to run native methods. It's probably required by some library (jar) you're using.
In here you can see not only a jar, but also the binary required by the jar. Pick the one for your platform.
To quote http://www.velocityreviews.com/forums/t143642-jni-unsatisfied-link-error-but-the-method-name-is-correct.html:
There are two things that cause UnsatisfiedLinkError. One is when
System.loadLibrary() fails to load the library, the other is when the
JVM fails to find a specific method in the library. The text of the
error message itself will indicate which is the case...
The error which you describe clearly cannot find the library at all. As the others have said, include it in your Java library path.
The other error—when the library can be found but the method within the library is not found—looks as follows:
java.lang.UnsatisfiedLinkError: myObject.method([Ljava/lang/Object;)V
In this case you either have the wrong method name, or will have to go back and add the method and recompile the code...