Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core

Viewed 1882

I have been working with OpenCV for quite a long time. But this is my first time using with java in eclipse. I followed this tutorial

To import OpenCV 4.1.0 in eclipse. I even search a lot of websites and they have the exact same steps. Every time I run the code I will get this **error*

    Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
        at abss123.Openc_importing.main(Openc_importing.java:18)
    Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 1 more

Some people were talking about changing the POM file or something but I didn't really understand. I found the POM file in the source file in opencv but not in the build which means need to build from source. I tried to load the "opencv_java410.dll" using System.load(...) command still didn't work

I also tried to add the Lib folder and the bin folder to my windows environment. But still, none of it worked. I will post my code and some command was commented to indicate that I tried it. I hope you can help me coz I'm stuck in this problem since yesterday.

package abss123;
import org.opencv.imgproc.Imgproc;
import org.opencv.video.*;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.imgcodecs.*;
import org.opencv.highgui.HighGui;
import java.io.*;

public class Openc_importing {

        public static void main(String args[]) {
        //LoadOpencv() ; 
        //nu.pattern.OpenCV.loadShared();
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 
        Mat image = new Mat(); 
        image = Imgcodecs.imread("MYPT000001.jpg"); 
        HighGui.imshow("First time", image);

    }

    static void LoadOpencv() {      
        System.load("C:\\opencv\\build\\java\\x64\\opencv_java410.dll");
    }
}
2 Answers

I had this error in version 3.4 or 4.2 of OpenCV and I solved the error by uninstall OpenCv 4.2 and install 3.2.0. The problem was solved.

I solve this problem by uninstalling everything, java and also eclibs and install them again. Then just follow the same mentioned tutorial.

Related