Java applet throws error in remove object from Iterator array -


welcome, programming simple rpg game in java applet. getting more , more complicated , many errors thrown face. today have problem .remove(); method.

exception in thread "awt-eventqueue-1" java.util.concurrentmodificationexception     @ java.util.arraylist$itr.checkforcomodification(unknown source)     @ java.util.arraylist$itr.remove(unknown source)     @ rpg.main.paint(main.java:365)     @ rpg.main.update(main.java:331)     @ sun.awt.repaintarea.updatecomponent(unknown source)     @ sun.awt.repaintarea.paint(unknown source)     @ sun.awt.windows.wcomponentpeer.handleevent(unknown source)     @ java.awt.component.dispatcheventimpl(unknown source)     @ java.awt.container.dispatcheventimpl(unknown source)     @ java.awt.component.dispatchevent(unknown source)     @ java.awt.eventqueue.dispatcheventimpl(unknown source)     @ java.awt.eventqueue.access$200(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.awt.eventqueue.dispatchevent(unknown source)     @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.run(unknown source) 

that's how error log looks like. code of program:

main.java

as can see error appears in paint methid in end of program, dont know maybe caused wrong initiation in beginning of program?

public void initlocatables() public void initlocatables2() 

and have admit called in main while loop in run method. these place error apears, , below in comment have included previous method has thrown error, both in remove();

for (iterator = locatablesarray.listiterator(); i.hasnext();) {                locatable l = (locatable) i.next();                 l.draw(g);                i.remove();             } /*while(itrlocatables.hasnext()) {     locatable l = itrlocatables.next();     l.draw(g);     l.remove(); }*/ 

thank reply.

maybe when call repaint() in run(), paint() queued edt , called possible; while iterating locatablesarray call initlocatables2() in run() done time , re-init of locatablesarray in same time code of paint() produce error.
advice separate init operation in specific init section , call once, run main loop.

just thing: why init iterator (class field itrlocatables) in initlocatables2()? use iterator when needed if possible.

hope clear, english not native language.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -