sarxos / webcam-capture

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.
http://webcam-capture.sarxos.pl
MIT License
2.26k stars 1.11k forks source link

Error: missing type WebcamException when I try to run Webcam.getDefault() #897

Open Thorium1717 opened 1 year ago

Thorium1717 commented 1 year ago

I am a junior programmer working on a personal project that requires me accessing a webcam in a java file. I found sarxos's webcam-capture and have downloaded it into my project folder. When I run my main class:

   import com.github.sarxos.webcam.Webcam;
   import java.io.File;
   import java.io.IOException;
   import javax.imageio.ImageIO;

  import com.github.sarxos.webcam.WebcamExceptionHandler;
  import com.github.sarxos.webcam.WebcamException; 

  public class Main {
  public static void main(String[] args) throws IOException{ 
    System.out.println("Start Pictures"); 

    Webcam webcam = Webcam.getDefault();

    if (webcam != null) {
        System.out.println("Webcam: " + webcam.getName());
    } else {
        System.out.println("No webcam detected");
    }
}

}

It gives me an error:

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

    The method getDefault() from the type Webcam refers to the missing type WebcamException
    at Main.main(Main.java:28)

I have tried running their example class that does the same thing and comes with the library: https://github.com/sarxos/webcam-capture/blob/master/webcam-capture/src/example/java/DetectWebcamExample.java

but it throws the same error

I have tried everything I can think of. If anyone else has run into this issue how did you solve it.