From d0cef1fe8289aa60f7db602fa1f0756943afe985 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Mon, 31 Oct 2022 12:43:13 +0100 Subject: [PATCH] fixed problems with file Path #43 --- .../zhaw/gartenverwaltung/json/PlantImageDeserializer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/json/PlantImageDeserializer.java b/src/main/java/ch/zhaw/gartenverwaltung/json/PlantImageDeserializer.java index e5611fc..f22cb35 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/json/PlantImageDeserializer.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/json/PlantImageDeserializer.java @@ -6,9 +6,11 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import javafx.scene.image.Image; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; public class PlantImageDeserializer extends JsonDeserializer { @@ -18,9 +20,9 @@ public class PlantImageDeserializer extends JsonDeserializer { Image result = null; URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText())); if (imageUrl != null) { - try (InputStream is = new FileInputStream(imageUrl.getFile())) { + try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) { result = new Image(is); - } catch (IllegalArgumentException e) { + } catch (IllegalArgumentException | URISyntaxException e) { // TODO: Log e.printStackTrace(); System.err.printf("Cannot find Image \"%s\"\n", imageUrl.getFile());