使用.remove方法时出错

时间:2012-05-26 08:16:32

标签: java

我正在用java开发一个客户端服务器聊天应用程序。但是,在编译其中一个java文件时,我收到错误:

Java文件:

    import java.net.*;
    import java.io.*;

    public class ChatServerThread extends Thread
   { 
   private ChatServer       server    = null;
   private Socket           socket    = null;
   private int              ID        = -1;
   private DataInputStream  streamIn  =  null;
   private DataOutputStream streamOut = null;

   public ChatServerThread(ChatServer _server, Socket _socket)
   {  super();
      server = _server;
      socket = _socket;
      ID     = socket.getPort();
   }
   public void send(String msg)
   {   try
       {  streamOut.writeUTF(msg);
          streamOut.flush();
       }
       catch(IOException ioe)
       {  System.out.println(ID + " ERROR sending: " + ioe.getMessage());
          server.remove(ID);
          stop();
       }
   }
   public int getID()
   {  return ID;
   }
   public void run()
   {  System.out.println("Server Thread " + ID + " running.");
      while (true)
      {  try
         {  server.handle(ID, streamIn.readUTF());
         }
         catch(IOException ioe)
         {  System.out.println(ID + " ERROR reading: " + ioe.getMessage());
            server.remove(ID);
            stop();
         }
      }
   }
   public void open() throws IOException
   {  streamIn = new DataInputStream(new 
                        BufferedInputStream(socket.getInputStream()));
      streamOut = new DataOutputStream(new
                        BufferedOutputStream(socket.getOutputStream()));
   }
   public void close() throws IOException
   {  if (socket != null)    socket.close();
      if (streamIn != null)  streamIn.close();
      if (streamOut != null) streamOut.close();
   }
   }

编译时出错:

C:\Assignment_2010HP93506>javac ChatServerThread.java
ChatServerThread.java:25: cannot find symbol
symbol  : method remove(int)
location: class ChatServer
          server.remove(ID);
                ^
ChatServerThread.java:36: cannot find symbol
symbol  : method handle(int,java.lang.String)
location: class ChatServer
         {  server.handle(ID, streamIn.readUTF());
                  ^
ChatServerThread.java:40: cannot find symbol
symbol  : method remove(int)
location: class ChatServer
            server.remove(ID);
                  ^
Note: ChatServerThread.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors

2 个答案:

答案 0 :(得分:2)

您的ChatServer课程没有remove(int)方法。确保它在那里。

答案 1 :(得分:0)

以下任何一种情况都可能属实:

  1. 您的类ChatServer没有删除和处理方法
  2. 您的类ChatServer具有名为remove和handle的方法,但它们没有与您调用它们完全相同的参数类型。
  3. 你已经改变了那个类但忘了编译它;你只是在这里编译ChatServerThread类。