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 7757045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:58:50+00:00 2026-06-01T12:58:50+00:00

im having a problem i havent been able to figure out a solution to.

  • 0

im having a problem i havent been able to figure out a solution to. Im making a small game where the object in _sballs ArrayList will be deleted if collided with another object called ball.
the problem i’ve encountered is that when the collision occur and when i attempt to remove the object from the ArrayList, the application crashes.

for(GObject sballgraphic : _sballs){
            Coordinates sballcoords = sballgraphic.getCoords();
            if(coords.getY() - coords._height > sballcoords.getY() + sballcoords._height && coords.getX() - coords._width > sballcoords.getX() + sballcoords._width){
                _sballs.remove(sballgraphic);
            }
        }

So the code compares the balls coordinates with all the sballs objects to check if there is a collision, then tries to remove the sball.

What is the problem here? 🙂

  • 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-06-01T12:58:51+00:00Added an answer on June 1, 2026 at 12:58 pm

    I’m guessing that the “crash” is a ConcurrentModificationException.

    It is happening because you are trying to remove from a collection while you are iterating over it with an iterator (the internal workings of the enhanced for).

    Your choices are:

    1. Iterate using an index (old-style for( i=0; i<_sballs.size(); i++ ))
    2. Iterate using an iterator explicitly, and use the iterator’s remove() method.
    3. Remember which items to remove by putting them into another list, and then use removeAll() after the loop is finished.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange problem and haven't been able to find anything about it
I have a problem that I haven't been able to find a solution to,
I'm having a problem with &. Basically I haven't been able to escape this
I've been developing a WS client using JAVA and I'm having a problem with
I'm having a problem with making a sha1-hash of a row in a select
having spent hours on this problem i need to throw it out to the
I've been having a problem with my media browser for weeks and haven't been
I haven't been able to find a question related to my specific problem. What
This is a problem I've been having for a while and I'm hoping someone
I've been working on this problem for awhile now, and haven't been able to

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.