remove string in list in awt java -
in application should remove string list when running on thread,but got exception like,
exception in thread "awt-eventqueue-0" java.lang.illegalargumentexception: item gh not found in list @ java.awt.list.remove(unknown source) @ org.sample.chatclient$updateclient$1.run(chatclient.java:200) @ java.awt.event.invocationevent.dispatch(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$000(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.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)
code:
final map<string, string> lihashmap=list; swingutilities.invokelater(new runnable() { @override public void run() { (entry<string, string> entry : lihashmap.entryset()) { string client_name=entry.getkey(); if(!checklist.containskey(client_name)) { lst.add(client_name + "\n"); checklist.put(client_name, ipaddress); } } (entry<string, string> entry : checklist.entryset()) { string client_name=entry.getkey(); if(!lihashmap.containskey(client_name)){ lst.remove(client_name);//remove string list checklist.remove(client_name); } }
the problem here. change this:
if(!lihashmap.containskey(client_name)){ lst.remove(client_name);//remove string list checklist.remove(client_name); }
to this:
if(lihashmap.containskey(client_name)){ lst.remove(client_name);//remove string list checklist.remove(client_name); }
i assuming hash map backing store of items removed list. right? therefore, should remove key if in hash map , in list.
if not way works, need maintain list of items should removed, , have verified are, in fact, in list, , remove them. this:
if(toberemovedmap.containskey(client_name)){ lst.remove(client_name);//remove string list checklist.remove(client_name); }
Comments
Post a Comment