有時候javafx項目運行正常,但是scenebuilder打開fxml文件時出現如下錯誤:
Open operation has failed.Make sure that the chosen file is a valid FXML document.
原因分析:
- 原因一、該fxml爲FXML Editer編輯,fxml中所引入的jar包均存在於項目的buildpath中,但是scenebuilder的Library Manager中未添加該jar包,因此項目可正常運行,但scenebuilder無法打開;
- 原因二、該fxml使用scenebuilder編輯,且scenebuilder中Library Manager也添加了必須的jar包,但後期jar包丟失因此無法打開。
解決方法:
舉例:如下圖fxml文件中引入了兩種類型的jar,其中第二種屬於javafx sdk中的組件,scenebuilder可以自動識別;但是第一種jar屬於第三方插件,scenebuilder不能識別,需要在Library Manager中添加相應的jar包。
操作步驟:
- 點擊Library的下三角,打開JAR/FXML Manager
- 選擇 Add Library/FXML from file system
此時便能順利打開FXML文件了