简体   繁体   English

JavaFX-MVC-如何从另一个包加载图像

[英]JavaFX - MVC - How can I load images from another package

I have a problem which appears when I export to runnable jar. 导出到可运行的jar时出现一个问题。

Basically I am creating a JavaFx Game which loads Images by using: 基本上,我正在创建一个JavaFx游戏,该游戏使用以下方式加载图像:

Image image = new Image(BlueCar.class.getResource("../resources/blueCar.png").toExternalForm()); 图片图片=新图片(BlueCar.class.getResource(“ ../ resources / blueCar.png”)。toExternalForm());

Everything works fine within eclipse. 在日食中一切正常。 However when I try to export and run it give a error on the line of code above. 但是,当我尝试导出并运行它时,在上面的代码行中给出了错误。

http://i.imgur.com/VbmGSO3.jpg http://i.imgur.com/VbmGSO3.jpg

I am using MVC Pattern for the application so I have packages separating the class from the images resources: 我正在为应用程序使用MVC模式,因此我有一些将类与图像资源分开的包:

http://i.imgur.com/gzm7d0s.jpg http://i.imgur.com/gzm7d0s.jpg

Please if you could help know what I am doing wrong please ? 请您帮我知道我做错了吗?

Jar文件系统不支持相对路径-使用绝对路径getClass()。getClassloader()。getResource(“ path / to / resource / blueCar.jpg”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM