ConcurrentModificationException errors

So I’m working on a little side-scrolling shooter and got some stuff working,
but now I got stuck in a problem. Whenever I want to remove something
from the bulletList, I get the ConcurrentModificationException. Also when
I want to shoot multiple bullets really fast, it crashes as well. I thought I
was doing this the right way, but it seems I’m doing something wrong.
bulletList declaration:


private List<Bullet> bulletList = new ArrayList<Bullet>();

Iterator:


public void tick() {
		// tickCount++;

		p.tick();
		player.tick();
		
		Iterator<Bullet> it = bulletList.iterator();
		while (it.hasNext()) {
			Bullet bullet = it.next();
			bullet.tick();
			
			if (!bullet.living) {
				bulletList.remove(bullet);
			}
		}
	}

Bullet.tick()


public void tick() {
		time--;
		if (time > 0) {
			moveBullet();
		} else {
			die();
		}
		System.out.println("Bullet Tick! Time: " + time);
	}

Die would only set the boolean living to false.
Does anyone know what I’m doing wrong?
Any help would be highly appreciated!

it.remove()

Alright, that was really helpful! It works now, but still I have the ConcurrentModificationException when I try to shoot really fast.

It’s because you’re trying to remove items while you’re looping through the list.

related post (ConcurrentModificationProblem with bullets): http://www.java-gaming.org/topics/indexoutofbounds-index-7-size-7-need-help/28638/msg/261156/view.html#msg261156

quotes from: http://www.java-gaming.org/topics/arraylist-vs-linkedlist/27016/msg/240144/view.html#msg240144

Posts require 10% of the contents be written by the poster. So, to remedy this, here’s a short story.

むかしむかし、亀は森の中にすんでいました。彼は遅い亀でした。終わりが。

Can’t comment without the related code, probably something similiar, or you’re adding and removing at the same time.