【发布时间】:2012-01-12 12:11:59
【问题描述】:
我已经创建了工作套接字,当我尝试发送文本或数字时,没问题,但是当我尝试发送我的自定义类对象时,我得到了 NullPointerException... 这是一些代码:
public boolean SendLi(List<Entity> list)
{
try {
out.writeObject(list);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Send: Error on OutputStream.write(byte[])");
}
return true;
}
public List<Entity> RecvLi()
{
List<Entity> data;
data = new ArrayList<Entity>();
try{
data = (List<Entity>) in.readObject();
} catch (IOException e) {
System.err.println("Send: Error on OutputStream.read(byte[]) - IOException");
return null;
} catch (ClassNotFoundException e) {
System.err.println("Send: Error on OutputStream.read(byte[]) - ClassNotFound");
e.printStackTrace();
}
return data;
}
实际上,我为列表编写的代码,但我想要一些类似的函数来发送其他对象。 感谢您的任何回复!
【问题讨论】:
标签: java sockets object arraylist