Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+14 votes

I try to add an image in Javafx but when my friend try to pull it, they couldn't see the image displays (but they still can see the code lines with image add)

asked in CSC305 Fall 2023 by (2.6k points)

3 Answers

+5 votes

When adding images in JavaFX, you should consider the path of the image file. It might be due to differences in the file paths. Make sure the image is in the repo.
Additionally load the images using:
Image image = new Image(getClass().getResource("/path/to/your/image.png").toString());

answered by (2.1k points)
+3

thank you! and the other don't have to download the image on their computer right?

+5

If you added the image to the project, preferably to the resources folder, if your teammate pulls the changes, they will automatically download the image files into their resources folder.

+4 votes

This usually happens when you get the file path wrong. Make sure you get the location of the image file right.

answered by (1 point)
0 votes

for the file paths use System.getProperty("user.dir") do get the file path for the project directory regardless of the user and + ""

answered by (2.3k points)
...