fixed problems with file Path

#43
This commit is contained in:
schrom01 2022-10-31 12:43:13 +01:00
parent 7a060be84a
commit d0cef1fe82
1 changed files with 4 additions and 2 deletions

View File

@ -6,9 +6,11 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonDeserializer;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
public class PlantImageDeserializer extends JsonDeserializer<Image> { public class PlantImageDeserializer extends JsonDeserializer<Image> {
@ -18,9 +20,9 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
Image result = null; Image result = null;
URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText())); URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText()));
if (imageUrl != null) { if (imageUrl != null) {
try (InputStream is = new FileInputStream(imageUrl.getFile())) { try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
result = new Image(is); result = new Image(is);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException | URISyntaxException e) {
// TODO: Log // TODO: Log
e.printStackTrace(); e.printStackTrace();
System.err.printf("Cannot find Image \"%s\"\n", imageUrl.getFile()); System.err.printf("Cannot find Image \"%s\"\n", imageUrl.getFile());