Search code examples
javaarraylistrectangles

Libgdx Array of Rectangles


I am doing collision detection, and I need an array of rectangles to loop through. It is not working and instead gives me a null pointer exception.
This is my code:

Array<Rectangle> rects = new Array();
Rectangle rect = new Rectangle();
rects.add(rect);

Solution

  • You need to change

    Array<Rectangle> rects = new Array();
    

    to

    Array<Rectangle> rects = new Array<Rectangle>();
    

    Also, why use Array instead of ArrayList?