I had the following code to capture an image using the webcam using Javacv. It was working without any issues but now it crashes with a NullPointerException
.
Code:
public class ClientTest {
public static void main(String[] args) {
takeImage();
}
public static ImageIcon takeImage() {
FrameGrabber grabber = null;
IplImage img = null;
ImageIcon image = null;
try {
grabber = FrameGrabber.createDefault(0);
} catch (com.googlecode.javacv.FrameGrabber.Exception e1) {
e1.printStackTrace();
}
int i = 0;
try {
grabber.start();
img = grabber.grab();
if (img != null) {
cvFlip(img, img, 1);
}
// Save image
image = new ImageIcon(img.getBufferedImage());
grabber.flush();
grabber.stop();
} catch (Exception e) {
Client.showMessage("Error taking image!");
e.printStackTrace();
}
return image;
}
}
Error:
Exception in thread "main" java.lang.NullPointerException
at com.googlecode.javacv.FrameGrabber.create(FrameGrabber.java:95)
at com.googlecode.javacv.FrameGrabber.createDefault(FrameGrabber.java:118)
at Main.ClientTest.takeImage(ClientTest.java:33)
at Main.ClientTest.main(ClientTest.java:24)
If anybody can shed some light I would greatly appreciate it, it is sort of a matter of urgency because it's part of my final year project which is due on Monday...
I just deleted all my .jar imports and reimported them. Everything seems to work now!