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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:53:49+00:00 2026-06-03T02:53:49+00:00

Say I have an ArrayList of blob objects, which I cycle through and draw

  • 0

Say I have an ArrayList of “blob” objects, which I cycle through and draw then onto the canvas.

     for (blob b:myBlobList)
     {
         canvas.drawCircle(b.X, b.Y, b.Size, paint);
     }

Also I have an onTouchListener that adds a new blob object whenever the surface is touched.

      if (event.getAction() == android.view.MotionEvent.ACTION_DOWN)
        {
          myBlobList.add(new blob());
          myBlobList.get(myBlobList.size()-1).X = event.getX();
          myBlobList.get(myBlobList.size()-1).Y = event.getY();;
        }

Yet together they cause a ConcurrentModificationException error. What would be your suggestion, how should I fix that?

Simply adding

try{ ... } catch (ConcurrentModificationException e) {}

Makes the screen/canvas flicker when this exception happens and it goes happen a lot. 🙂

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-06-03T02:53:50+00:00Added an answer on June 3, 2026 at 2:53 am

    It seems that you add a new blob to your list while iterating over that list. One simple workaround would be to make a copy of the list before the loop. If you add items while iterating they will not be taken into account.

    List<Blob> myBlobCopy = new ArrayList<Blob>(myBlobList); //copies the content
    for (Blob b : myBlobCopy) {
        canvas.drawCircle(b.X, b.Y, b.Size, paint);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an ArrayList of USBDevice Objects. Each USBDevice has ProductID and VendorID
For simplicity, say I have an ArrayList that contains objects of type A, B
Say I have a generic array like this: ArrayList<Fruit> fruits = new ArrayList<Fruit>(); Then
I have an ArrayList, and we'll say it can be at most size 5.
Suppose I have an ArrayList of objects of size n. Now I want to
I have one ArrayList in Session, lets say for example [305,306,380] . On submit,
Let's say I have two same strings inside an ArrayList... is there a way
Say I have a couple of basic objects like so: [Serializable] public class Base
So let's say I have an ArrayList full of Products that need to be
To make it easy, lets say I have an arraylist allBooks containing class books

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.