I get this error
Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown
protocol: c at javafx.scene.image.Image.validateUrl(Image.java:1097)
at javafx.scene.image.Image.<init>(Image.java:598)
at javafx.scene.image.ImageView.<init>(ImageView.java:164)
at fileshare_client.fx.pkg1.UploadappUI_1Controller.iconimagebuttonAction(UploadappUI_1Controller.java:355)" java:355
which is
imageview=new ImageView(iconimage.getAbsolutePath());"
here's my code:
@FXML
private AnchorPane mainAnchorpane;
@FXML
private ImageView imageview;
private File iconimage;
@FXML
public void iconimagebuttonAction(ActionEvent event) {
FileChooser filechooser = new FileChooser();
iconimage = filechooser.showOpenDialog(mainAnchorpane.getScene().getWindow());
System.out.println(iconimage.getName());
if (iconimage != null) {
String iconimagepath = iconimage.getAbsolutePath();
System.out.println(iconimagepath);
**imageview=new ImageView(iconimage.getAbsolutePath());**// error
}
}
Using
gives you the absolute path of the file, where as the constructor expects a
file URL
Try using
or append
file:
to the absolute path