2012-05-26 57 views
0

我正在用java開發一個客戶端服務器聊天應用程序。但是在編譯java文件我收到錯誤之一:使用.remove方法時出錯

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

想必你'ChatServer'類沒有一個'用單'int'參數remove'方法。我們很難說任何其他的東西,因爲你沒有向我們展示那個類...... –

+1

它說'ChatServer'沒有'remove(int)'方法也沒有'handle(int,String)''方法。 – assylias

回答

2

ChatServer類沒有一個remove(int)方法。確保它在那裏。

+0

謝謝大家......我明白了! –

0

下列任一可能爲真:

  1. 你的類的ChatServer沒有刪除和處理方法
  2. 你的類的ChatServer有方法稱爲刪除和處理,但他們不具備完全相同的參數類型,你調用它們。
  3. 您已更改該類,但忘記編譯它;你只在這裏編譯ChatServerThread類。