0

I'm trying to implement a very simple interface to Raspberry Pi in JavaFX. I'm using an .fxml based layout and styling my items with css. My problem is despite the app works perfectly in my main computer(running from eclipse) it's not working on Raspberry nor when I try to run the exported jar on main computer.

This is how I skinned my button. Ofcourse resources/images folder is in my building path. The buttons has the color what I described in css, but the image is not loading.

.imageButton1 {
-fx-background-color: blue;
-fx-graphic: url('file:resources/images/temperature.png');}

It give me the following error:

WARNING: Error loading image: file:resources/images/temperature.png

I uploaded my project into dropbox

2
  • What JDK version are you using on the Raspberry Pi? Commented Feb 25, 2015 at 18:40
  • Java(TM) SE Runtime Environment (build 1.8.0_06-b23) Java HotSpot(TM) Client VM (build 25.6-b23, mixed mode) Commented Feb 25, 2015 at 21:28

2 Answers 2

2

The problem with your project is in the resources folder. Being outside the source folder is not found.

This is how I made it work:

Created a JavaFX project in NetBeans, and moved the resource folder inside the source one. So this is Source Packages:

-Source Packages
    +me.noip.blase
    +me.noip.blase.view
    +resources.images

and then changed all references from file: to "/":

primaryStage.getIcons().add(new Image("/resources/images/icon.png"));

and the css file:

.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;
}

Now it works fine in both desktop and Raspberry Pi.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried what you suggested and maybe i did something wrong or i cant reproduce what you think. I changed the references to / and tried to make the same structure as yours. Here's a picture about my current structure But i still got the Error loading image error messages
Why is there an empty resources folder? Shouldn't that one have the image files?
It seems a strange way that eclipse show the structure of the project, but that isnt really empty, because if i delete that, my src/resources/images folder disappear too.
I don't use Eclipse, so I can't tell. What I did was just having a regular package with images. Maybe when you put it outside src, it's not added to the jar.
Can you upload your project somewhere? Maybe I can find out from that. (since I'm trying to load images with / instead of file: , the pictures arent loading when I lunch the app in the IDE)
0

I will accept your solution as an answer, I tried importing to NetBeans and it worked, but I cannot reproduce that under Eclipse. Meanwhile I found another question here and followed that solution and it works(I dont know how I didn't find that before, I massively googled for a day)

I will leave this here if anyone else searchs for this.

Thank you very much for your time and help :)

1 Comment

Thanks for posting back, it looks like the solution you mention is also inserting the resources within the source folder (you can call it "resources" or not).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.