Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.ConcurrentModificationException

807606Apr 10 2007 — edited Apr 10 2007
Not sure what this error is all about its a new one for me anyway

Prisoners:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:3
72)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at Prison.ReleasePrisoners(Prison.java:165)
at TestPrison2.main(TestPrison2.java:185)

		public void ReleasePrisoners(String id) //search for prisoner by ID
		{
			System.out.println("Prisoners:");
			for (Person x: thePersons) 
			{
				//System.out.println("Found person: " + x.toString());
				if (x instanceof Prisoner) 
					{
						Prisoner p = (Prisoner) x;
						//System.out.println("Found prisoner: " + p.toString());
						//if (p.getPrisonerID() == id ) 
						//p.getPrisonerID()equals(id)
						{
							if (p.getPrisonerID().equals(id)) //Checks if there is a matching ID within the enetered 
							{
								if(p.getDaysLeft()<7)
								{
									thePersons.remove(x);
								}
								else
								{
									System.out.println("\nThat prisoner cannot be released as he still has "+p.getDaysLeft()+" days left to serve.");
								}
							} 
						}
					}
				else if (x instanceof HRPrisoner)
					{
						Prisoner p = (Prisoner) x;
						//System.out.println("Found prisoner: " + p.toString());
						//if (p.getPrisonerID() == id ) 
						//p.getPrisonerID()equals(id)
						{
							if (p.getPrisonerID().equals(id)) //Checks if there is a matching ID within the enetered 
							{
								if(p.getDaysLeft()<7)
								{
									thePersons.remove(x);
								}		
								else
								{
									System.out.println("\nThat prisoner cannot be released as he still has "+p.getDaysLeft()+" days left to serve.");
								}
							}
						}
					}
			}
		}
Thankyou for your help in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 8 2007
Added on Apr 10 2007
12 comments
155 views