Kum*_*ado 1 url javafx runtime-error image invalid-url
我得到这个错误
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(Uploadapp??UI_1Controller.java:355)" java:355
Run Code Online (Sandbox Code Playgroud)
这是
imageview=new ImageView(iconimage.getAbsolutePath());"
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@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
}
}
Run Code Online (Sandbox Code Playgroud)
使用
iconimage.getAbsolutePath()
Run Code Online (Sandbox Code Playgroud)
为您提供文件的绝对路径,如构造函数期望的那样, file URL
尝试使用
iconimage.toURI().toString()
Run Code Online (Sandbox Code Playgroud)
或追加file:
到绝对路径
"file:" + iconimage.getAbsolutePath()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2715 次 |
最近记录: |