Hi Nima,

You can't modify your list using iterator, because it changes the
state and the iterator "gets confused", so you're getting the
exception. If you want to populate the list, do a simple loop and
invoke add(Object) method. Use iterator only to read list content, or
update objects stored in the list, but do not change list's state
while traversing the iterator.

Adam

On 3/20/06, Nima Boustanian <[EMAIL PROTECTED]> wrote:
> Hey all
>
> I keep getting this java.util.ConcurrentModificationException when I try
> to add rows to a table. The below code won't
> work, but if I remove the For loop and just add "result.add(new
> ConversationsPlaceHolderTable("test")); it will output
> "test" as the first row in my table. I Googled a bit and found a post by
> Kent Tong saying that this probably is because I am
> trying to modify a collection while an iterator is trying to iterate
> over it, but I can't figure out how this should be resolved in my
> IBasicTableModel
> class. Any ideas?
>
>  public Iterator getCurrentPageRows(int firstRow, int rowsPerPage,
>            ITableColumn sortColumn, boolean sortOrder) {
>
>         List result = new ArrayList();
>
>         for (Iterator it = postList.iterator(); it.hasNext(); ) {
>             Post post = (Post)it.next();
>             postList.add(post);
>             result.add(new ConversationsPlaceHolderTable(post.getTitle()));
>         }
>
>         return result.iterator();
>     }
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to