I’m following natureofcode book and I’m trying to make an exercise where some objects are shot out of a cannon.
The main issue I’m facing is that when I verify for mousePressed, I add to an ArrayList a new bullet object.
After this, I want to use the object from the ArrayList but I get IndexOutOfBoundsException. So here is my code:
Thanks for your quick reply. Apparently it’s working, but I still don’t understand, why do I have to check if the size is greater than 0, to use the object inside the ArrayList !?