【发布时间】:2015-04-13 21:25:58
【问题描述】:
正如docs.oracle 所说的关于图像类:
// load an image in background, displaying a placeholder while it's loading
// (assuming there's an ImageView node somewhere displaying this image)
// The image is located in default package of the classpath
Image image1 = new Image("/flower.png", true);
我在github 分享了我的简单项目,因此您可以轻松访问代码。
这是我的一段代码:
splashScreen = new Image("/gravixsplash.png");
splashScreenBackplate = new ImageView();
splashScreenBackplate.setImage(splashScreen);
instructionLayer = new Image("/gravixinstructions.png");
splashScreenTextArea = new ImageView();
splashScreenTextArea.setImage(instructionLayer);
但这不适合我,我明白了:
原因:java.lang.IllegalArgumentException:在 javafx.scene.image.Image.validateUrl(Image.java:1081) 处找不到无效的 URL 或资源
在 (Image.java:1081) 我发现这个:
if (resource == null) {
throw new IllegalArgumentException("Invalid URL or resource not found");
}
我假设我的 url(resource) 出于某种原因等于 null,但它并没有帮助我找到解决方案。
(也许不知何故我需要打开 javaFX8,我怀疑 intellijIDEA 构建 javaFX2 项目,我在设置中搜索,但没有找到任何东西)
【问题讨论】:
-
项目中的图像不在类路径的根目录中,它们在
/ru/petrsu/javafxGame/中。你试过了吗:new Image("/ru/petrsu/javafxGame/gravixsplash.png") -
@jewelsea thx,现在一切正常!非常感谢!
标签: java image intellij-idea javafx javafx-8