gpt4 book ai didi

java - 使用 .remove 方法时出错

转载 作者:行者123 更新时间:2023-12-02 07:46:30 24 4
gpt4 key购买 nike

我正在用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

最佳答案

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

关于java - 使用 .remove 方法时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10764719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com