Note that there are some explanatory texts on larger screens.

plurals
  1. POError on ArrayList
    primarykey
    data
    text
    <h2>for IndexOutOfBoundsException:</h2> <p>Hi i'm making a space invader like game and i have a problem when a bullet collides with the enemy. Here is the code:</p> <pre><code>for (int i = 0; i &lt; enemies.size(); i++) { for (int j = 0; j &lt; bullets.size(); j++) { if (collidesWith(bullets.get(j), enemies.get(i))) { //Line 81 The Error Occurred here enemies.remove(i); bullets.remove(j); addScore(1); } } } </code></pre> <p>Code for the Colliding:</p> <pre><code>public static boolean collidesWith(Entity collider, Entity collided) { Rectangle hitBox1 = collider.getHitbox(); Rectangle hitBox2 = collided.getHitbox(); return hitBox1.intersects(hitBox2); } </code></pre> <p>Code for the Hitbox:</p> <pre><code>@Override public Rectangle getHitbox() { return new Rectangle(getX(), getY(), getWidth(), getHeight()); } </code></pre> <p>The Error Messages:</p> <pre><code>Exception in thread "Thread-4" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 at java.util.ArrayList.rangeCheck(ArrayList.java:635) at java.util.ArrayList.get(ArrayList.java:411) at io.github.kjordo711.game.Main.run(Main.java:81) at java.lang.Thread.run(Thread.java:724) </code></pre> <p>I think the error cause by 2 or more bullets hits the enemy</p> <h2>for OutOfMemoryError:</h2> <p>The Player can shoot too many bullets at once if they hold Space the bullet will keep shooting without delaying i could limit the bullet spawning but the problem is even with 10 bullets max on screen the error still occur, i tried to delay it with</p> <pre><code>Thread.sleep(500); </code></pre> <p>but it just sleep all the game thread</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload