| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1746 人关注过本帖
标题:有谁能告诉我这个异常是什么意思?(我已把源代码贴出来,希望大家能帮我看 ...
只看楼主 加入收藏
wu1011
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-11-18
结帖率:80%
收藏
 问题点数:0 回复次数:10 
有谁能告诉我这个异常是什么意思?(我已把源代码贴出来,希望大家能帮我看看)
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]]
搜索更多相关主题的帖子: 源代码 
2008-03-11 09:07
cll19820814
Rank: 2
等 级:新手上路
威 望:3
帖 子:328
专家分:0
注 册:2005-11-30
收藏
得分:0 
不是都告诉你了就是这个东东了,java.lang.lllegalARrgumentException
查下API,一下就清楚了,也不是很困难吧??

懵懵懂懂,看千遍而不会;设身处地,试一下就成功!
2008-03-11 09:16
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
非法参数异常:item Thread-4在列表中没有找到

I'm here, as always...
2008-03-11 09:32
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
把你的例子贴出来..

学习需要安静。。海盗要重新来过。。
2008-03-11 09:52
wu1011
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-11-18
收藏
得分:0 
//服务端
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();
      
    }
}
2008-03-11 22:01
wu1011
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-11-18
收藏
得分:0 
回复 4# 的帖子
我把例子贴出来了
你给看看!!!
2008-03-11 22:02
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
..item Thread-4 not found in list
    at java.awt.List.remove<Unknown Sourse>//没得到删除list得到事件源
    at MyClient.<init><MyClient.java:113>其它的你查查帮助啊...我很长时间不弄了....不好意思
    at MyClient.main<MyClient.java:139>
你想把下线的用户删除...触发了该错误..我发觉你每次上线的人提示线程都是thread-2你查查是不是这地方错了

[[it] 本帖最后由 sunkaidong 于 2008-3-12 09:55 编辑 [/it]]

学习需要安静。。海盗要重新来过。。
2008-03-11 23:10
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
System.out.println("@@@@"+ex);           
                   
                try{
                    
                  socket.close();
                  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()+"下线了");
                  System.out.println("系统提示:"+this.getName()+"下线了");
                  }
                  }
           
               }catch(IOException e){
                   
                  System.out.println("**"+e);
               }
这样改就不会抱错了..但是细节还是有问题...是逻辑上的..你自己改啊...

学习需要安静。。海盗要重新来过。。
2008-03-12 11:11
wu1011
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-11-18
收藏
得分:0 
回复 8# 的帖子
还是会报错
你只开来两个客户端的话
不会报错
但你多开两个 3-4个
你关一个
就会报错
2008-03-12 13:11
wu1011
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2007-11-18
收藏
得分:0 
回复 8# 的帖子
我找到错误了
是Server端在某客户下线后发给其他客户时
多发了一次客户下线的信息
那在其他没下线的客户在第一次收到服务端的下线信息
在列表中删掉已下线的客户后
又一次接受到先前那个客户下线的信息
又会进行一次删除
但列表中已经没有那个已下线的客户
所以会报在List中没有找到 的 异常

呵呵
谢谢你哦
2008-03-15 13:35
快速回复:有谁能告诉我这个异常是什么意思?(我已把源代码贴出来,希望大家能帮 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022917 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved