Results 1 to 6 of 6
Thread: Why i get an error?
- 01-28-2010, 10:04 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
Why i get an error?
I have this code, if i remove from my program, it execute correctly.
for (BaseCell c : cells) {
if (c != null) {
BaseCell progeny = c.replicate();
if (progeny != null)
newCells.add(progeny);
}
}
cells.addAll(newCells);
When i try to execute this part of code, i get this error:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification( AbstractList.java:449)
at java.util.AbstractList$Itr.next(AbstractList.java: 420)
at Sim.run(Sim.java:127)
at Sim.main(Sim.java:175)
Some ideas? I think that the problem is when returning the object or something like that.
- 01-28-2010, 10:23 PM #2
Hmm.. Well, we don't know what BaseCell is and I'm anticipating newCells is a list and cells is an array of BaseCell. With those assumptions made, I'll try explaining what that code does in english and maybe then you can find the dilemma.
This is a for-each loop. Element X will be stored in the BaseCell c until it loops again. If element X is not null, it will make a new BaseCell called progeny and it will have c.replicate(). And a list called newCells will add w/e progeny is, which should be the same as BaseCell c (replicate means copy).Java Code:for (BaseCell c : cells) { if (c != null) { BaseCell progeny = c.replicate(); if (progeny != null) newCells.add(progeny); } }
I have no idea what that is. If cells is an array (it should be), then addAll() method does nothing because there is no method called addAll() in Arrays.Java Code:cells.addAll(newCells);
Arrays (Java Platform SE 6)"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 01-29-2010, 12:13 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
Thanks you, is all i need.
- 01-29-2010, 08:03 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
addAll().
That code as presented doesn't look to me like it should give you a ConcurrentModificationException, so I'm guessing we're missing the relevant bit of code.
- 01-29-2010, 08:10 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 01-29-2010, 09:06 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
Similar Threads
-
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM -
error 530 error authentication required
By rgale in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-12-2008, 04:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks