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

  • SEARCH
  • Home
  • 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 336075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:12:30+00:00 2026-05-12T10:12:30+00:00

I am developing a 2D grid based sim game. Progress is good. Been cracking

  • 0

I am developing a 2D grid based sim game. Progress is good.
Been cracking out code for the last few days really well, and I’ve been having some issues today.

I build two rooms, set the door position, and spawn a person. The person has the 2 room types that they must visit in order to be cured (It’s a remake of Theme Hospital).
I click the spawn button, Person moves onto the grid from off screen, and then when the spawn is finished, they get their first path to the first room, then second, and then back to the ending spawn point.

When I say the spawn point, I mean the point off screen / off grid, when I say the ending spawn point, I mean the point where the person is when the spawn cycle is finished, and they are fully on screen / grid.

The problem now comes, what to do with the “person” (which is an object in its own right), is finished with? Should I simple set a boolean so they are no longer “active” but data on them remains? I wasn’t sure, so I tried to just remove them from the ArrayList of people objects they were being held in.

I did this by assigning a number value to each person on creation which was the same as their new position in the ArrayList, and then when removing them, using that number. I know that in itself is floored, but I’m only testing with 1 person right now. If anyone can give me some help on that, fantastic! But I suppose that is more a sub question.

When the person is to be removed, they are, and I check the size of the arraylist, and then I get the following error… “Exception in thread “AWT-EventQueue-0″ java.util.ConcurrentModificationException”

I did some researching and I understand this is to do with synchronisation of objects in different threads, but I’m not sure that I have more than one thread. I do have a single timer, and I don’t think the people ArrayList is accessed elsewhere.

Any Thoughts? Ideas? Suggestions? Comments on this?

Thanks in advance!

(I will soon post a video and update this question with a link to it)

  • 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-12T10:12:30+00:00Added an answer on May 12, 2026 at 10:12 am

    Typically I give every person or entity or whatever a boolean field called isMarkedForDeletion. Then during the main loop, they will either be told to update(), or if they are marked for deletion their index will be added to a deletion list. Once you have the deletion list all populated, you can iterate through the deletion list and remove those objects from the main list. Alternatively you can just iterate backwards and pull from the tail end of the list.

    This may or may not explain your ConcurrentModificationException – I’ve never gotten them when working with ArrayList’s before. However, I’ve gotten them from LinkedList’s and it was precisely for the reason you described and had nothing to do with threads. The actual cause was using an Iterator. The following will cause a ConcurrentModificationException:

    for (Iterator i = list.iterator(); i.hasNext();)
    {
        Person o = i.next();
    
        o.update();
    
        if (list.isMarkedForDeletion())
        {
            list.remove(o);
        }
    }
    

    This will not cause an Exception:

    ArrayList deletedObjects = new ArrayList();
    for (Iterator i = list.iterator(); i.hasNext();)
    {
        Person o = i.next();
    
        o.update();
    
        if (list.isMarkedForDeletion())
        {
            deletedObjects.add(o);
        }
    }
    
    for (int i = 0; i < deletedObjects.size(); i++)
    {
        list.remove(deletedObjects.get(i));
    }
    

    Perhaps the simplest way to do it, will not cause an Exception:

    for (int i = list.size()-1; i >= 0; i--)
    {
        Person o = list.get(i);
    
        if (o.isMarkedForDeletion())
        {
            list.remove(i);
        }
        else
        {
            o.update();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 216k
  • Answers 216k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You would have to call a CFC that would return… May 12, 2026 at 11:05 pm
  • Editorial Team
    Editorial Team added an answer Click on File -> Update Preview. When the process completes,… May 12, 2026 at 11:05 pm
  • Editorial Team
    Editorial Team added an answer The usual style to writing jQuery plugins would mean that… May 12, 2026 at 11:05 pm

Related Questions

I am developing a 2d game for iPhone by using cocos2d. I use many
I am developing a 2D iPhone game by using cocos2d. I need a countdown
I am developing a timer in Delphi 2009. I am currently using the following
I'm developing a 2D game for the iPhone using OpenGL ES and I'd like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.