KolemanPa
KolemanPa

Reputation: 48

Array List wont recognize photos when using file path

My program creates a Black Jack game using a JavaFX GUI, however when I am inputting photos into the deck (ArrayList) it is not populating the ArrayList with the image paths. The paths are all very similar, they are c1.png or c2.png etc.

        for (int i = 0; i < 13; i++) {
            deck.add(new Image("file:images/c" + (i+1) + ".png"));
        }

It should display images into JavaFX GUI when hard coded it works, but won't work in for loop

Upvotes: 0

Views: 60

Answers (1)

acarlstein
acarlstein

Reputation: 1838

Try:

for (int i = 0; i < 13; i++) {
  deck.add(new Image(new FileInputStream("C:\\images\\" + (i+1) + ".png"));
}

Also, make sure to cast your ArrayList as ArrayList<Image>:

List<Image> deck = new ArrayList<Image>();

Let me know if this helps you out.

Upvotes: 1

Related Questions