Java网络编程之简易聊天室
零零散散做了一周,这个问题一直解决不了,实在不知道是哪里出了问题。
package com.company.Client.tools;
import com.company.Client.view.FriendList;
import com.company.Client.view.TalkingView;
import com.company.Shared.Message;
import java.io.ObjectInputStream;
import java.net.Socket;
/**
* @Title:
* @Package
* @Description:客户端连接到服务器线程(对应ConnectThread)
* @author: Yeeasy
**/
public class UserThreads extends Thread {
private Socket socket;
ObjectInputStream in;
public UserThreads(Socket socket){
this.socket=socket;
}
public void run() {
while (true) {
try {
//接收ConnectThread来的信息
in = new ObjectInputStream(socket.getInputStream());
Message msg = (Message) in.readObject();
if(msg.getMsgType().equals("onlineSet")){
//修改用户列表好友在线状态
FriendList friendList=FriendListManage.getFriendList(msg.getUser());
System.out.println("进入更新列表");
friendList.UpdateFriendList(msg);
}else if(msg.getMsgType().equals("talk")){
System.out.println( msg.getUser()+"说:" + msg.getContent());
TalkingView talkingView=TalkingViewManage.getTalkingView(msg.getUser()+" "+msg.getFriend());
talkingView.showMessage(msg);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public Socket getSocket() {
return socket;
}
}
结果就是 friendList.UpdateFriendList(msg)报空指针
加个!null判断,进入了UpdateFriendList,但是还是不会更新好友列表
下面是源码,可能看起来花点时间,麻烦了
[](链接: https://pan.baidu.com/s/1U9EwsWh5gZQLUonm5WhwHg?pwd=5sgh 提取码: 5sgh 复制这段内容后打开百度网盘手机App,操作更方便哦)