工作,我想提出一個圖像上的標籤,而代碼:相對URL不是JavaFX中
Label userPic = new label();
ImageView userImage = new ImageView(
new Image("test/123/headPortrait.png",50.0,50.0,false,false));
userPic.setGraphic(userImage);
但它不斷地拋出java.lang.IllegalArgumentException: Invalid URL or resource not found.
我已經試過file://headPortrait.png
,file://E:/eclipse/ClassSchedule/headPortrait.png
(絕對URL)。這次編譯器沒有拋出任何異常,但圖像仍然不顯示,應用程序運行速度非常緩慢。
在我嘗試添加圖片到標籤之前,我所有的代碼都完美地工作。
有效的URL是'E:/eclipse/ClassSchedule/headPortrait.png'或'/ test/123/headPortrait.png'而不是你寫的 – azro
可能的重複[JavaFX 8圖像加載(找不到無效的URL或資源)](https://stackoverflow.com/questions/28489402/javafx-8-image-load-invalid-url-or-resource-not-found) –