以下是我一直在尝试做的事情:
常用代码
//定义自定义类对象的数组CoOrdinates类在服务器和客户端(android应用程序)中定义
ArrayList<CoOrdinates> Loc_Positions = new ArrayList<CoOrdinates>
服务器端
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(Loc_Coordinates);
final byte[] data = baos.toByteArray();
packet = new DatagramPacket(data, data.length, address, port);
socket.send(packet);
客户端
DatagramPacket packet2 = new DatagramPacket(buf2, buf2.length);
socket.receive(packet2);
byte[] data = packet2.getData();
ByteArrayInputStream baos = new ByteArrayInputStream(data);
ObjectInputStream oos = new ObjectInputStream(baos);
Loc_Coordinates = (ArrayList<CoOrdinates>) oos.readObject();
问题
//找不到类异常
对象从客户端发送到服务器,但是当在服务器端获取对象时,(ObjectInputStream oos
)对象为null,并且(Loc_Coordinates行)导致异常错误。