multithreading - removing items from combo box in java 8 -


so i'm making small game better @ programming , trying put in way use items. i'm trying use combo box , want hpotion , mpotion taken out of combo box when used keep error says "exception in thread "javafx application thread" java.lang.indexoutofboundsexception". code

string[] itemsarray = {"sword","wand","hpotion","mpotion"};  combobox<string> cbo = new combobox<>();  observablelist<string> items= fxcollections.observablearraylist(itemsarray); cbo.getitems().add(items.get(0)); cbo.getitems().add(items.get(1)); cbo.getitems().add(items.get(2)); cbo.getitems().add(items.get(3)); buttons.getchildren().add(cbo);  //the items given effects cbo.setonaction((actionevent e)->{     string selected = cbo.getvalue();      switch (selected) {         case "sword":             player.setpower(player.getpower()+10);             break;         case "wand":             player.setmagicpower(player.getmagicpower()+10);             break;         case "hpotion":             player.heal(20);             textarea.appendtext("you have healed 20.\n");             cbo.getitems().remove(selected);             break;         case "mpotion":             player.restoremana(20);             textarea.appendtext("you regained 20 mana.\n");             cbo.getitems().remove(selected);             break;     }  }); 

and if try select mpotion runs code hpotion , gives error "exception in thread "javafx application thread" java.lang.unsupportedoperationexception" along "javafx application thread" java.lang.indexoutofboundsexception" error.

this stack trace.

exception in thread "javafx application thread" java.lang.unsupportedoperationexception @ java.util.collections$unmodifiablelist.add(collections.java:1314) @ javafx.collections.listchangebuilder.nextremove(listchangebuilder.java:208) @ javafx.collections.observablelistbase.nextremove(observablelistbase.java:150) @ javafx.collections.modifiableobservablelistbase.remove(modifiableobservablelistbase.java:181) @ javafx.collections.modifiableobservablelistbase.remove(modifiableobservablelistbase.java:171) @ javagame.javagame.lambda$start$0(javagame.java:151) @ javagame.javagame$$lambda$77/904592364.handle(unknown source) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:49) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.node.fireevent(node.java:8216) @ javafx.scene.control.comboboxbase.valueinvalidated(comboboxbase.java:136) @ javafx.scene.control.comboboxbase$1.invalidated(comboboxbase.java:161) @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:111) @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:145) @ javafx.scene.control.comboboxbase.setvalue(comboboxbase.java:167) @ javafx.scene.control.combobox.updatevalue(combobox.java:468) @ javafx.scene.control.combobox.access$300(combobox.java:187) @ javafx.scene.control.combobox$4.changed(combobox.java:453) @ com.sun.javafx.binding.expressionhelper$generic.firevaluechangedevent(expressionhelper.java:361) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:81) @ javafx.beans.property.readonlyobjectwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyobjectwrapper.java:176) @ javafx.beans.property.readonlyobjectwrapper.firevaluechangedevent(readonlyobjectwrapper.java:142) @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:112) @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:145) @ javafx.scene.control.selectionmodel.setselecteditem(selectionmodel.java:102) @ javafx.scene.control.combobox$comboboxselectionmodel.lambda$new$152(combobox.java:499) @ javafx.scene.control.combobox$comboboxselectionmodel$$lambda$74/1327995285.invalidated(unknown source) @ com.sun.javafx.binding.expressionhelper$singleinvalidation.firevaluechangedevent(expressionhelper.java:137) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:81) @ javafx.beans.property.readonlyintegerwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyintegerwrapper.java:176) @ javafx.beans.property.readonlyintegerwrapper.firevaluechangedevent(readonlyintegerwrapper.java:142) @ javafx.beans.property.integerpropertybase.markinvalid(integerpropertybase.java:113) @ javafx.beans.property.integerpropertybase.set(integerpropertybase.java:146) @ javafx.scene.control.selectionmodel.setselectedindex(selectionmodel.java:68) @ javafx.scene.control.singleselectionmodel.updateselectedindex(singleselectionmodel.java:215) @ javafx.scene.control.singleselectionmodel.select(singleselectionmodel.java:149) @ javafx.scene.control.singleselectionmodel.clearandselect(singleselectionmodel.java:103) @ javafx.scene.control.combobox$comboboxselectionmodel$1.onchanged(combobox.java:535) @ javafx.collections.weaklistchangelistener.onchanged(weaklistchangelistener.java:88) @ com.sun.javafx.collections.listlistenerhelper$generic.firevaluechangedevent(listlistenerhelper.java:329) @ com.sun.javafx.collections.listlistenerhelper.firevaluechangedevent(listlistenerhelper.java:73) @ javafx.collections.observablelistbase.firechange(observablelistbase.java:233) @ javafx.collections.listchangebuilder.commit(listchangebuilder.java:482) @ javafx.collections.listchangebuilder.endchange(listchangebuilder.java:541) @ javafx.collections.observablelistbase.endchange(observablelistbase.java:205) @ javafx.collections.modifiableobservablelistbase.remove(modifiableobservablelistbase.java:183) @ javafx.collections.modifiableobservablelistbase.remove(modifiableobservablelistbase.java:171) @ javagame.javagame.lambda$start$0(javagame.java:156) @ javagame.javagame$$lambda$77/904592364.handle(unknown source) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:49) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.node.fireevent(node.java:8216) @ javafx.scene.control.comboboxbase.valueinvalidated(comboboxbase.java:136) @ javafx.scene.control.comboboxbase$1.invalidated(comboboxbase.java:161) @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:111) @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:145) @ javafx.scene.control.comboboxbase.setvalue(comboboxbase.java:167) @ javafx.scene.control.combobox.updatevalue(combobox.java:468) @ javafx.scene.control.combobox.access$300(combobox.java:187) @ javafx.scene.control.combobox$4.changed(combobox.java:453) @ com.sun.javafx.binding.expressionhelper$generic.firevaluechangedevent(expressionhelper.java:361) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:81) @ javafx.beans.property.readonlyobjectwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyobjectwrapper.java:176) @ javafx.beans.property.readonlyobjectwrapper.firevaluechangedevent(readonlyobjectwrapper.java:142) @ javafx.beans.property.objectpropertybase.markinvalid(objectpropertybase.java:112) @ javafx.beans.property.objectpropertybase.set(objectpropertybase.java:145) @ javafx.scene.control.selectionmodel.setselecteditem(selectionmodel.java:102) @ javafx.scene.control.combobox$comboboxselectionmodel.lambda$new$152(combobox.java:499) @ javafx.scene.control.combobox$comboboxselectionmodel$$lambda$74/1327995285.invalidated(unknown source) @ com.sun.javafx.binding.expressionhelper$singleinvalidation.firevaluechangedevent(expressionhelper.java:137) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:81) @ javafx.beans.property.readonlyintegerwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyintegerwrapper.java:176) @ javafx.beans.property.readonlyintegerwrapper.firevaluechangedevent(readonlyintegerwrapper.java:142) @ javafx.beans.property.integerpropertybase.markinvalid(integerpropertybase.java:113) @ javafx.beans.property.integerpropertybase.set(integerpropertybase.java:146) @ javafx.scene.control.selectionmodel.setselectedindex(selectionmodel.java:68) @ javafx.scene.control.singleselectionmodel.updateselectedindex(singleselectionmodel.java:215) @ javafx.scene.control.singleselectionmodel.select(singleselectionmodel.java:149) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin.lambda$createlistview$304(comboboxlistviewskin.java:654) @ com.sun.javafx.scene.control.skin.comboboxlistviewskin$$lambda$172/1428006824.invalidated(unknown source) @ com.sun.javafx.binding.expressionhelper$generic.firevaluechangedevent(expressionhelper.java:349) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(expressionhelper.java:81) @ javafx.beans.property.readonlyintegerwrapper$readonlypropertyimpl.firevaluechangedevent(readonlyintegerwrapper.java:176) @ javafx.beans.property.readonlyintegerwrapper.firevaluechangedevent(readonlyintegerwrapper.java:142) @ javafx.beans.property.integerpropertybase.markinvalid(integerpropertybase.java:113) @ javafx.beans.property.integerpropertybase.set(integerpropertybase.java:146) @ javafx.scene.control.selectionmodel.setselectedindex(selectionmodel.java:68) @ javafx.scene.control.multipleselectionmodelbase.select(multipleselectionmodelbase.java:357) @ javafx.scene.control.multipleselectionmodelbase.clearandselect(multipleselectionmodelbase.java:325) @ com.sun.javafx.scene.control.behavior.cellbehaviorbase.simpleselect(cellbehaviorbase.java:242) @ com.sun.javafx.scene.control.behavior.cellbehaviorbase.doselect(cellbehaviorbase.java:206) @ com.sun.javafx.scene.control.behavior.cellbehaviorbase.mousepressed(cellbehaviorbase.java:132) @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(behaviorskinbase.java:95) @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(behaviorskinbase.java:89) @ com.sun.javafx.event.compositeeventhandler$normaleventhandlerrecord.handlebubblingevent(compositeeventhandler.java:218) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:80) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.scene$mousehandler.process(scene.java:3724) @ javafx.scene.scene$mousehandler.access$1500(scene.java:3452) @ javafx.scene.scene.impl_processmouseevent(scene.java:1728) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2461) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:348) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:273) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:382) @ com.sun.glass.ui.view.handlemouseevent(view.java:553) @ com.sun.glass.ui.view.notifymouse(view.java:925) @ com.sun.glass.ui.win.winapplication._runloop(native method) @ com.sun.glass.ui.win.winapplication.lambda$null$141(winapplication.java:102) @ com.sun.glass.ui.win.winapplication$$lambda$38/96639997.run(unknown source) @ java.lang.thread.run(thread.java:745) exception in thread "javafx application thread" java.lang.indexoutofboundsexception @ com.sun.javafx.scene.control.readonlyunbackedobservablelist.sublist(readonlyunbackedobservablelist.java:136) @ javafx.collections.listchangelistener$change.getaddedsublist(listchangelistener.java:242) @ com.sun.javafx.scene.control.behavior.listviewbehavior.lambda$new$174(listviewbehavior.java:258) @ com.sun.javafx.scene.control.behavior.listviewbehavior$$lambda$183/355246484.onchanged(unknown source) @ javafx.collections.weaklistchangelistener.onchanged(weaklistchangelistener.java:88) @ com.sun.javafx.collections.listlistenerhelper$generic.firevaluechangedevent(listlistenerhelper.java:329) @ com.sun.javafx.collections.listlistenerhelper.firevaluechangedevent(listlistenerhelper.java:73) @ com.sun.javafx.scene.control.readonlyunbackedobservablelist.callobservers(readonlyunbackedobservablelist.java:75) @ javafx.scene.control.multipleselectionmodelbase.clearandselect(multipleselectionmodelbase.java:331) @ com.sun.javafx.scene.control.behavior.cellbehaviorbase.simpleselect(cellbehaviorbase.java:242) @ com.sun.javafx.scene.control.behavior.cellbehaviorbase.doselect(cellbehaviorbase.java:206) @ com.sun.javafx.scene.control.behavior.cellbehaviorbase.mousepressed(cellbehaviorbase.java:132) @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(behaviorskinbase.java:95) @ com.sun.javafx.scene.control.skin.behaviorskinbase$1.handle(behaviorskinbase.java:89) @ com.sun.javafx.event.compositeeventhandler$normaleventhandlerrecord.handlebubblingevent(compositeeventhandler.java:218) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:80) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.scene$mousehandler.process(scene.java:3724) @ javafx.scene.scene$mousehandler.access$1500(scene.java:3452) @ javafx.scene.scene.impl_processmouseevent(scene.java:1728) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2461) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:348) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:273) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:382) @ com.sun.glass.ui.view.handlemouseevent(view.java:553) @ com.sun.glass.ui.view.notifymouse(view.java:925) @ com.sun.glass.ui.win.winapplication._runloop(native method) @ com.sun.glass.ui.win.winapplication.lambda$null$141(winapplication.java:102) @ com.sun.glass.ui.win.winapplication$$lambda$38/96639997.run(unknown source) @ java.lang.thread.run(thread.java:745) 


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -