报错
今天在使用JAVAFX的时候,想更换程序图标。查找了相关资料发现以下的代码会抛出RunTime异常。捕捉了其中的异常信息为Invalid URL: unknown protocol: c
try{
Image ix = new Image("Path");
stage.getIcons().add(ix);
}catch (RuntimeException e){
System.out.println(e.getMessage());
}
查了很久的资料,得到如下解决办法:
解决方法
try{
File f = new File("Path");
Image ix = new Image(f.toURI().toString());
stage.getIcons().add(ix);
}catch (RuntimeException e){
System.out.println(e.getMessage());
}