From 9e869ae69be47e8260beec404f822da87acb31df Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 7 Apr 2021 09:56:51 +0200 Subject: [PATCH] handle no camera detected better --- .../com/sparrowwallet/sparrow/control/WebcamService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java index 467b391e..7c23685f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java @@ -18,6 +18,7 @@ import javafx.scene.image.Image; import java.awt.image.BufferedImage; import java.util.Arrays; +import java.util.List; import java.util.concurrent.TimeUnit; public class WebcamService extends ScheduledService { @@ -47,7 +48,12 @@ public class WebcamService extends ScheduledService { protected Image call() throws Exception { try { if(cam == null) { - cam = Webcam.getWebcams(1, TimeUnit.MINUTES).get(0); + List webcams = Webcam.getWebcams(1, TimeUnit.MINUTES); + if(webcams.isEmpty()) { + throw new UnsupportedOperationException("No camera available."); + } + + cam = webcams.get(0); cam.setCustomViewSizes(resolution.getSize()); cam.setViewSize(resolution.getSize()); if(!Arrays.asList(cam.getWebcamListeners()).contains(listener)) {