0

When I hardcode the images (no for loop) the game works perfectly. I tested the for loop on an array of numbers and it worked perfectly. When I add the images, including the image variables, the app crashes, even though Android Studio says the app installed successfully. What am I missing here? I have the ArrayList for frontImage as well. Thank you.

private void cardFront() {

    for (int i = 0; i < 9; i++) {
        int random = (int) (Math.random() * (drivers.length));
        if (!frontImage.contains(drivers[random])) {
            frontImage.add(drivers[random]);
            frontImage.add(drivers[random]);
        } else {
            i--;
        }
        image11 = frontImage.get(1);
        image12 = frontImage.get(2);
        image13 = frontImage.get(3);
        image14 = frontImage.get(4);
        image15 = frontImage.get(5);
        image16 = frontImage.get(6);
        image17 = frontImage.get(7);
        image18 = frontImage.get(8);
        image19 = frontImage.get(9);
        image21 = frontImage.get(10);
        image22 = frontImage.get(11);
        image23 = frontImage.get(12);
        image24 = frontImage.get(13);
        image25 = frontImage.get(14);
        image26 = frontImage.get(15);
        image27 = frontImage.get(16);
        image28 = frontImage.get(17);
        image29 = frontImage.get(18);
    }
}
  • Does this answer your question? [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – a_local_nobody May 26 '20 at 05:07
  • the app installing has nothing to do with it crashing, there's a difference between runtime and compile time :) – a_local_nobody May 26 '20 at 05:07
  • It doesn't, but I think I asked the wrong question. I'm stuck as to why the loop works for a number array but not for an image array. I run the number loop and I get an array of 10 numbers, each unique. I use an image array in place of the number array and get nothing. – Patrick McMahon May 27 '20 at 05:31
  • well numbers aren't images and vice versa, so yes, the implementation will be different depending on the data structure used – a_local_nobody May 27 '20 at 05:36

0 Answers0