JavaFX 图像加载错误
JavaFX image loading error
我正在尝试在 JavaFX 中实现 Raspberry Pi 的一个非常简单的接口。我正在使用基于 .fxml 的布局,并使用 css 为我的项目设置样式。我的问题是,尽管该应用程序在我的主计算机上运行良好(运行ning 来自 eclipse),但它无法在 Raspberry 上运行,也无法在我尝试 运行 主计算机上导出的 jar 时运行。
这就是我为按钮设置皮肤的方式。当然 resources/images 文件夹在我的构建路径中。按钮具有我在 css 中描述的颜色,但未加载图像。
.imageButton1 {
-fx-background-color: blue;
-fx-graphic: url('file:resources/images/temperature.png');}
它给我以下错误:
WARNING: Error loading image: file:resources/images/temperature.png
我将我的项目上传到 dropbox
您的项目的问题出在资源文件夹中。在源文件夹之外未找到。
我是这样工作的:
在 NetBeans 中创建了一个 JavaFX 项目,并将资源文件夹移动到源文件夹中。这是源码包:
-Source Packages
+me.noip.blase
+me.noip.blase.view
+resources.images
然后将所有引用从 file:
更改为“/”:
primaryStage.getIcons().add(new Image("/resources/images/icon.png"));
和 css 文件:
.imageButton1 {
-fx-background-color: blue;
-fx-graphic: url('/resources/images/temperature.png');
}
.imageButton2 {
-fx-graphic: url('/resources/images/gear.png');
-fx-background-color: red;
}
.imageButton3 {
-fx-graphic: url('/resources/images/power.png');
-fx-background-color: black;
}
.imageButton4 {
-fx-graphic: url('/resources/images/diagram.png');
-fx-background-color: green;
}
现在它在桌面和 Raspberry Pi 中都可以正常工作。
我会接受您的解决方案作为答案,我尝试导入到 NetBeans 并且它有效,但我无法在 Eclipse 下重现它。与此同时,我在这里发现了另一个问题并遵循了该解决方案并且它有效(我不知道我以前怎么没有找到它,我大量搜索了一天)
如果有人搜索这个,我会留下这个here。
非常感谢您的宝贵时间和帮助:)
我正在尝试在 JavaFX 中实现 Raspberry Pi 的一个非常简单的接口。我正在使用基于 .fxml 的布局,并使用 css 为我的项目设置样式。我的问题是,尽管该应用程序在我的主计算机上运行良好(运行ning 来自 eclipse),但它无法在 Raspberry 上运行,也无法在我尝试 运行 主计算机上导出的 jar 时运行。
这就是我为按钮设置皮肤的方式。当然 resources/images 文件夹在我的构建路径中。按钮具有我在 css 中描述的颜色,但未加载图像。
.imageButton1 {
-fx-background-color: blue;
-fx-graphic: url('file:resources/images/temperature.png');}
它给我以下错误:
WARNING: Error loading image: file:resources/images/temperature.png
我将我的项目上传到 dropbox
您的项目的问题出在资源文件夹中。在源文件夹之外未找到。
我是这样工作的:
在 NetBeans 中创建了一个 JavaFX 项目,并将资源文件夹移动到源文件夹中。这是源码包:
-Source Packages
+me.noip.blase
+me.noip.blase.view
+resources.images
然后将所有引用从 file:
更改为“/”:
primaryStage.getIcons().add(new Image("/resources/images/icon.png"));
和 css 文件:
.imageButton1 {
-fx-background-color: blue;
-fx-graphic: url('/resources/images/temperature.png');
}
.imageButton2 {
-fx-graphic: url('/resources/images/gear.png');
-fx-background-color: red;
}
.imageButton3 {
-fx-graphic: url('/resources/images/power.png');
-fx-background-color: black;
}
.imageButton4 {
-fx-graphic: url('/resources/images/diagram.png');
-fx-background-color: green;
}
现在它在桌面和 Raspberry Pi 中都可以正常工作。
我会接受您的解决方案作为答案,我尝试导入到 NetBeans 并且它有效,但我无法在 Eclipse 下重现它。与此同时,我在这里发现了另一个问题并遵循了该解决方案并且它有效(我不知道我以前怎么没有找到它,我大量搜索了一天)
如果有人搜索这个,我会留下这个here。
非常感谢您的宝贵时间和帮助:)