简体   繁体   English

网络聊天编程

[英]Network Chat Programming

learning to network program from TheCherno's Network chat programming series and I got to 24 without any issues and everything is the same, then when I launched the server and connected to it with a localhost IP, it gave me an exception in thread "receive".从 TheCherno 的网络聊天编程系列学习网络程序,我到了 24 岁,没有任何问题,一切都一样,然后当我启动服务器并使用本地主机 IP 连接到它时,它在线程“接收”中给了我一个异常。 Here is the exact error.这是确切的错误。

Exception in thread "receive" java.lang.NullPointerException
at com.josh.chat.server.Server.process(Server.java:93)
at com.josh.chat.server.Server.access$2(Server.java:87)
at com.josh.chat.server.Server$2.run(Server.java:59)

I know it connects because it tells me the Identifier and that only works if the client connects to the server, but the server isn't giving any feedback.我知道它连接是因为它告诉我标识符,并且只有在客户端连接到服务器时才有效,但服务器没有提供任何反馈。 What is the problem?问题是什么? Here is my code .这是我的代码

You never assign a value to clients :您永远不会为clients分配价值:

List<ServerClient> clients;

Try:尝试:

List<ServerClient> clients = new ArrayList<>();

(And learn how to debug your code). (并学习如何调试您的代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM