有谁能告诉我这个异常是什么意思?(我已把源代码贴出来,希望大家能帮我看看)
Exception in thread "main" java.lang.lllegalARrgumentException: item Thread-4 not found in list at java.awt.List.remove<Unknown Sourse>
at MyClient.<init><MyClient.java:113>
at MyClient.main<MyClient.java:139>
//服务端
import *;
import javax.swing.*;
import java.awt.*;
import *;
import java.util.*;
import java.awt.event.*;
public class MyRoomServer extends JFrame{
JTextArea Msgjta,Acjta,Logjta;
JScrollPane Msgjsp,Acjsp,Logjsp,UserListjsp;
JButton send,cancel,reset,clear;
JLabel Msglab,Aclab,Loglab,Userlab;
JPanel panel1,panel2,panel3;
java.awt.List UserList;
JPanel panel21,panel22,panel23;
String Actemp = "";
Vector allClient = new Vector();
MyRoomServer(){
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
setLayout(new BorderLayout(10,10));
getContentPane().add(panel1,BorderLayout.NORTH);
getContentPane().add(panel2,BorderLayout.CENTER);
getContentPane().add(panel3,BorderLayout.SOUTH);
panel1.setLayout(new BorderLayout());
Msgjta = new JTextArea();
Msglab = new JLabel("Message Log");
Msgjsp = new JScrollPane(Msgjta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel1.add(Msglab,BorderLayout.NORTH);
panel1.add(Msgjsp,BorderLayout.CENTER);
panel2.setLayout(new BorderLayout(10,10));
panel21 = new JPanel();
panel22 = new JPanel();
panel23 = new JPanel();
panel2.add(panel21,BorderLayout.WEST);
panel2.add(panel22,BorderLayout.CENTER);
panel21.setLayout(new BorderLayout());
Userlab = new JLabel("Client List");
UserList = new java.awt.List(10,false);
UserListjsp = new JScrollPane(UserList,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel21.add(Userlab,BorderLayout.NORTH);
panel21.add(UserListjsp,BorderLayout.CENTER);
panel23.setLayout(new GridLayout(2,2));
send = new JButton("SEND");
cancel = new JButton("CANCEL");
reset = new JButton("RESET");
clear = new JButton("CLEAR");
panel23.add(send);
panel23.add(cancel);
panel23.add(reset);
panel23.add(clear);
panel22.setLayout(new BorderLayout());
Aclab = new JLabel("Announcement");
Acjta = new JTextArea();
Acjsp = new JScrollPane(Acjta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel22.add(Aclab,BorderLayout.NORTH);
panel22.add(Acjsp,BorderLayout.CENTER);
panel22.add(panel23,BorderLayout.SOUTH);
panel3.setLayout(new BorderLayout());
Logjta = new JTextArea();
Loglab = new JLabel("Operating Log");
Logjsp = new JScrollPane(Logjta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel3.add(Loglab,BorderLayout.NORTH);
panel3.add(Logjsp,BorderLayout.CENTER);
setTitle("Server");
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
ButtonListener sendButton = new ButtonListener();
send.addActionListener(sendButton);
try{
ServerSocket serversocket = new ServerSocket(8000);
Logjta.append("Server started at" + new Date() + "\n");
int clientNo = 1;
while(true){
Socket socket = serversocket.accept();
Logjta.append("Client" + clientNo + " come at" + new Date() + "\n");
InetAddress inetaddress = socket.getInetAddress();
Logjta.append("Client" + clientNo + "'s IP is " + inetaddress.getHostAddress() + "\n");
ClientThread thread = new ClientThread(socket);
thread.start();
// UpdateClient updateclient = new UpdateClient();
// updateclient.start();
clientNo++;
}
}catch(IOException ex){
System.out.println(ex);
}
}
class ClientThread extends Thread{
private Socket socket;
PrintWriter outMessage;
String temp = "";
public ClientThread(Socket socket){
this.socket = socket;
}
public void run(){
try{
allClient.add(this);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
outMessage = new PrintWriter(socket.getOutputStream());
UserList.add(this.getName());
//向当前客户发送其他客户信息(不包括当前客户自己的信息)
for(int i =0;i<allClient.size()-1;i++){
ClientThread tempThread = (ClientThread)allClient.elementAt(i);
sendword("系统提示:"+tempThread.getName()+"来了");
}
//向其他客户发送当前客户的信息(包括当前用户自己的信息)
sendWordToEveryone("系统提示:"+this.getName()+"来了");
while(true){
temp = in.readLine();
Msgjta.append(temp);
if(temp.indexOf("对大家说") != -1){
sendWordToEveryone(temp);
}
}
}catch(IOException ex){
System.out.println("@@@@"+ex);
try{
socket.close();
}catch(IOException e){
System.out.println("**"+e);
}
int reset_index = allClient.indexOf(this);//删除已下线的用户
allClient.remove(reset_index);
UserList.remove(this.getName());
Enumeration one = allClient.elements();//向在线的用户发送下线用户信息
while(one.hasMoreElements()){
Object tempObject = one.nextElement();
if(tempObject != null){
ClientThread tempThread = (ClientThread)tempObject;
sendWordToEveryone("系统提示:"+this.getName()+"下线了");
}
}
}
}
private void sendword(String str){
outMessage.println(str);
outMessage.flush();
}
}
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
Actemp = Acjta.getText().trim();
sendWordToEveryone(Actemp);
}
}
void sendWordToEveryone(String str){ //群发
Enumeration one = allClient.elements();
while(one.hasMoreElements()){
Object tempObject = one.nextElement();
if(tempObject != null){
ClientThread tempThread = (ClientThread)tempObject;
if(tempThread.isAlive()){
tempThread.sendword(str);
}
}
}
}
/* class UpdateClient extends Thread{
public void run(){
Enumeration one = allClient.elements();
while(one.hasMoreElements()){
Object tempObject = one.nextElement();
if(tempObject != null){
ClientThread tempThread = (ClientThread)tempObject;
if(tempThread.isAlive()){
sendWordToEveryone("系统提示:"+tempThread.getName()+"来了");
}
}
}
}
}*/
public static void main(String args[]){
new MyRoomServer();
}
}
//客户端
import *;
import javax.swing.*;
import java.awt.*;
import *;
import java.util.*;
import java.awt.event.*;
public class MyClient extends JFrame{
JTextArea Msgjta,MsgLogjta;
JScrollPane Msgjsp,MsgLogjsp,UserListjsp;
JButton send,cancel,filesend;
JLabel Msglab,MsgLoglab,UserListlab,Targetlab;
JPanel panel1,panel2,panel3;
java.awt.List UserList;
JRadioButton Unicast,P2P;
JPanel panel21,panel22,panel23,panel23button;
JTextField Targettf;
BufferedReader in;
PrintWriter outMessage;
Socket socket;
String inMessage = "";
String Username = "";
String OtherUser = "";
MyClient(){
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
setLayout(new BorderLayout(10,10));
getContentPane().add(panel1,BorderLayout.WEST);
getContentPane().add(panel2,BorderLayout.CENTER);
getContentPane().add(panel3,BorderLayout.SOUTH);
panel1.setLayout(new BorderLayout(10,10));
UserListlab = new JLabel("Client List");
UserList = new java.awt.List(10,false);
UserListjsp = new JScrollPane(UserList,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel1.add(UserListlab,BorderLayout.NORTH);
panel1.add(UserListjsp,BorderLayout.CENTER);
panel21 = new JPanel();
panel21.setLayout(new BorderLayout(10,10));
Targetlab = new JLabel("Target");
Targettf = new JTextField();
panel21.add(Targetlab,BorderLayout.NORTH);
panel21.add(Targettf,BorderLayout.CENTER);
panel22 = new JPanel();
panel22.setLayout(new FlowLayout(FlowLayout.LEFT,5,10));
Msglab = new JLabel("Message");
Unicast = new JRadioButton("Unicast");
Unicast.setSelected(true);
P2P = new JRadioButton("P2P");
ButtonGroup group = new ButtonGroup();
group.add(Unicast);
group.add(P2P);
filesend = new JButton("filesend");
panel22.add(Msglab);
panel22.add(Unicast);
panel22.add(P2P);
panel22.add(filesend);
panel23button = new JPanel();
panel23button.setLayout(new FlowLayout(FlowLayout.CENTER,5,10));
send = new JButton("send");
cancel = new JButton("cancel");
panel23button.add(send);
panel23button.add(cancel);
panel23 = new JPanel();
panel23.setLayout(new BorderLayout(10,10));
Msgjta = new JTextArea();
Msgjsp = new JScrollPane(Msgjta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel23.add(panel22,BorderLayout.NORTH);
panel23.add(Msgjsp,BorderLayout.CENTER);
panel23.add(panel23button,BorderLayout.SOUTH);
panel2.setLayout(new BorderLayout(10,10));
panel2.add(panel21,BorderLayout.NORTH);
panel2.add(panel23,BorderLayout.CENTER);
panel3.setLayout(new BorderLayout());
MsgLogjta = new JTextArea();
MsgLoglab = new JLabel("Message Log");
MsgLogjsp = new JScrollPane(MsgLogjta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel3.add(MsgLoglab,BorderLayout.NORTH);
panel3.add(MsgLogjsp,BorderLayout.CENTER);
setTitle("Client");
setSize(700,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
ButtonListener sendMessage = new ButtonListener();
send.addActionListener(sendMessage);
try{
socket = new Socket("127.0.0.1",8000);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
outMessage = new PrintWriter(socket.getOutputStream());
while(true){
inMessage = in.readLine().trim();
if(inMessage.indexOf("系统提示:") != -1 && inMessage.indexOf("来了") != -1){
OtherUser = inMessage.substring(5,inMessage.indexOf("来"));
UserList.add(OtherUser);
}
else if(inMessage.indexOf("系统提示:") != -1 && inMessage.indexOf("下线了") != -1){
OtherUser = inMessage.substring(5,inMessage.indexOf("下"));
UserList.remove(OtherUser);
}
MsgLogjta.append(inMessage + "\n");
}
}catch(IOException ex){
System.out.println(ex);
}
}
class ButtonListener implements ActionListener{
String who = "";
public void actionPerformed(ActionEvent e){
if(Unicast.isSelected()){
who = "对大家说";
}
else if(P2P.isSelected()){
who = "对某某说";
}
String temp = who + Msgjta.getText().trim();
outMessage.println(temp);
outMessage.flush();
Msgjta.setText("");
}
}
public static void main(String args[]){
new MyClient();
}
}
[[it] 本帖最后由 wu1011 于 2008-3-11 22:05 编辑 [/it]]