JavaFX很新,我在运行后显示图像时遇到了一些麻烦。这是给我带来麻烦的方法。
private void lookUp(Site site) {
String link = site.getLink();
String imageName = link.replace("/", "1");
imageName = imageName.replace(".", "4");
imageName = imageName.replace(":", "3");
if(site.getImagePath() != null){
//what to do if this shit does have an image already
System.out.println("sample/Resources/images/" + site.getImagePath() + ".jpg");
String imagePath = "/sample/Resources/images/" + site.getImagePath() + ".jpg";
imagePath.trim();
System.out.println(site.getImagePath());
System.out.println(System.getProperty("user.dir"));
Image image = new Image(imagePath);
webShot.setImage(image);
}
else{
//What to do if the image doesn't exist
Snapshot service = new Snapshot();
service.setLink(site.getLink());
service.setOnSucceeded(t -> {
System.out.println("done:" + t.getSource().getValue());
site.setImagePath(t.getSource().getValue().toString());
progressToScreenShot.setProgress(100);
progressToScreenShot.setOpacity(0);
Image image = new Image("src/sample/Resources/images/" + site.getImagePath() + ".jpg");
webShot.setImage(image);
});
service.setOnRunning(t -> {
progressToScreenShot.setOpacity(1.0);
progressToScreenShot.setProgress(service.getProgress());
});
service.start();
}//End of Else
}
奇怪的是第二次运行,图像保存到文件夹,它将出现在菜单中。该服务使用名为grabItz的API返回网站的快照。给出的错误是网址Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
但是,如果它是一个无效的URL或资源不存在,它是如何在第二次运行时出现的?