在我的应用程序中,我应该在线程上运行时从列表中删除一个字符串,但是我得到了这样的异常,
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: item gh not found in list
at java.awt.List.remove(Unknown Source)
at org.sample.ChatClient$updateClient$1.run(ChatClient.java:200)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
代码:
final Map<String, String> liHashMap=list;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (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);
}
}
for (Entry<String, String> entry : checkList.entrySet()) {
String client_Name=entry.getKey();
if(!liHashMap.containsKey(client_Name)){
lst.remove(client_Name);//Remove string from list
checkList.remove(client_Name);
}
}