Sunday, 29 September 2013

Sockets ClassCastException HashMap

Sockets ClassCastException HashMap

I've created a serverSocket and accept a client connection. However when I
try to read from the client, it is throwing the following exception. If I
change HashMap to ArrayList, it does not work either.
Exception in thread "Thread-3" java.lang.ClassCastException:
java.awt.Point cannot be cast to java.util.HashMap
at ServerSide.Server.getPoints(Server.java:112)
at ServerSide.Server.run(Server.java:69)
//...
public void getPoints() throws IOException, ClassNotFoundException {
points = (HashMap<Point, Boolean>) objectInputStream.readObject();
Iterator iterator = points.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Point, Boolean> currentPoint = (Map.Entry<Point,
Boolean>) iterator.next();
currentPoint.setValue(firgure.isHit(currentPoint.getKey().x,
currentPoint.getKey().y));
}
objectOutputStream.writeObject(points);
}
P.s. Sorry for my English.

No comments:

Post a Comment