Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7540963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:46:17+00:00 2026-05-30T07:46:17+00:00

I am making a 2D and currently working on shooting with bullets. The bullet

  • 0

I am making a 2D and currently working on shooting with bullets. The bullet is a seperate class. All the bullets are stored in an arraylist called bullets. I am trying to make it destroy itself when it is out of the side of the screen (< -16), but when I try it gives me this error.

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.next(Unknown Source)
at GameCanvas.updateMovement(GameCanvas.java:94)
at GameCanvas.gameLoop(GameCanvas.java:63)
at GameCanvas.<init>(GameCanvas.java:28)
at GameClient.<init>(GameClient.java:68)
at GameClient.main(GameClient.java:29)

I assume it has something do with when it is being destroy, I am using this code to destroy it:

public void move() {

    if(x > -16) {
        x -= move_speed;
    } else {
        kill();
    }

}

public void kill() {
    ObjectHandler.bullets.remove(this);
}

updateMovement() method:

public void updateMovement() {
    PlayerObject.update();

    for(Bullet bullet : ObjectHandler.bullets) {
        bullet.move();


    }

}

Why is it doing this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:46:18+00:00Added an answer on May 30, 2026 at 7:46 am

    This happens because you are modifying a list while you’re iterating over it.

    Try to “remember” what you need to kill and after you’ve passed the whole list, go through your “memory” and perform the appropriate kills. This way you will modify the list after iterating over it.

    E.g.:

    public void move() {
    
        if(x > -16) {
            x -= move_speed;
        } else {
            ObjectHandler.remember_to_kill(this);
        }
    
    }
    
    // in ObjectHandler:
    
    private HashSet<type_of_object_to_kill> kill_memory = new...;
    
    public void remember_to_kill() {
        this.kill_memory.add(this);
    }
    
    private void kill_from_memory() {
        for (type_of_object_to_kill obj: kill_memory) {
            ObjectHandler.bullets.remove(this);
        }
        ObjectHandler.kill_memory.clear();
    }
    
    // update movement:
    
    public void updateMovement() {
        PlayerObject.update();
    
        for(Bullet bullet : ObjectHandler.bullets) {
            bullet.move();
        }
        ObjectHandler.kill_from_memory();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a profile for my website. I am trying to
I am currently working on making my code contain more generics. I encountered a
I am currently working on a site and i'm making a login system. I
I am currently working on a silverlight client, making use of a web server,
Im currently working on making a flash platformer engine...but my collision detect needs some
I'm currently working on my GUI for this Sudoku solver I'm making. I've managed
I am currently working on an OPENGL ES 2.0 project. I am making a
I am currently working on an android project and making use of the SlidingDrawer
I have a project I'm currently working on, which I am contemplating making open
I'm in the process of making a music app and I'm currently working on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.