Exception in thread "main" java.lang.Error: Unresolved compilation problems

import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.photo.Photo;
import org.opencv.imgproc.Imgproc;


public class ImageEnhancement {
    public static void main(String[] args) {
        // Load the image
        Mat image = Imgcodecs.imread("/home/charith/Desktop/Opencv/source/1.jpeg", Imgcodecs.IMREAD_COLOR);

        // Convert image to grayscale
        Mat grayscale = new Mat();
        Imgproc.cvtColor(image, grayscale, Imgproc.COLOR_BGR2GRAY);

        // Remove creases
        Mat denoised = new Mat();
        Photo.fastNlMeansDenoising(grayscale, denoised);

        // Enhance image quality
        Mat enhanced = new Mat();
        Imgproc.equalizeHist(denoised, enhanced);

        // Save the enhanced image
        Imgcodecs.imwrite("/home/charith/Desktop/Opencv/enhanced/edited.jpeg", enhanced);

        System.out.println("Image enhancement completed.");
    }
}

This is a simple java program which I have written to get rid of mottles and creases and then enhance the quality of image. But when I run it using visual studio code my integrated console displays below error messages. Can you please help me resolve this?

 /usr/bin/env /usr/lib/jvm/java-11-openjdk-amd64/bin/java -cp /tmp/vscodesws_463bd/jdt_ws/jdt.ls-java-project/bin ImageEnhancement 
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        Mat cannot be resolved to a type
        Imgcodecs cannot be resolved
        Imgcodecs cannot be resolved to a variable
        Mat cannot be resolved to a type
        Mat cannot be resolved to a type
        Imgproc cannot be resolved
        Imgproc cannot be resolved to a variable
        Mat cannot be resolved to a type
        Mat cannot be resolved to a type
        Photo cannot be resolved
        Mat cannot be resolved to a type
        Mat cannot be resolved to a type
        Imgproc cannot be resolved
        Imgcodecs cannot be resolved

        at ImageEnhancement.main(ImageEnhancement.java:10)

your cmdline does not link opencv-java.jar, also you need something like this in Main() to load the jni bindings:

Hi, Thank you so much for your reply. I setup OPENCV_DIR & LD_LIBRARY_PATH to include opencv installation directory and opencv library path respectively and ran my program. In the main function before anything else I included System.loadLibrary(Core.Native_LIBRARY_NAME); as well but I still keep getting the same error as before.

yea, that’s step #2, step #1 is still: link your java against opencv-java.jar

I included opencv-java.jar file in the classpath while compiling my code and now I am getting the below error.

An exception has occurred in the compiler (11.0.19). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.nio.file.ReadOnlyFileSystemException
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.checkWritable(ZipFileSystem.java:175)
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.newOutputStream(ZipFileSystem.java:543)
at jdk.zipfs/jdk.nio.zipfs.ZipPath.newOutputStream(ZipPath.java:859)
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newOutputStream(ZipFileSystemProvider.java:282)
at java.base/java.nio.file.Files.newOutputStream(Files.java:220)
at jdk.compiler/com.sun.tools.javac.file.PathFileObject.openOutputStream(PathFileObject.java:469)
at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1739)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:757)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1631)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1599)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
I have given all read,write,execute permissions to all the files and directories inside my project.

drwxrwxrwx 2 charith charith 4096 May 17 22:37 enhanced
-rwxrwxrwx 1 charith charith 1191 May 21 11:06 ImageEnhancement.class
-rwxrwxrwx 1 charith charith 971 May 20 16:05 ImageEnhancement.java
drwxrwxrwx 2 charith charith 4096 May 17 22:37 source

please show, how you did that

I simply ran the below command when compiling.

javac -cp /usr/share/java/opencv-420.jar ImageEnhancement.java

Hi,

When I ran it with root privilages (sudo javac) it copiled with no issues. I think that error message did not give any hint over what was going wrong. What it said was totally irrelevant. Thank you so much for your help.