1
votes

I'm trying to make an online drawing game. For that I'm using the Path class in Android and I need to send it to my Java server. To do that, I had tried to extend the Path class, as follows:

public class SerializedPath extends Path implements Serializable {
    private static final long serialVersionUID = -5974912367682897467L;
}

To simplify things and to narrow down the problem, all I did was to send it with outputStream.writeObject(new SerializedPath) and then outputStream.flush() where outputStream is an instance of ObjectOutputStream. Over the server I simply read it using inputStream.readObject() where inputStream is an instance of ObjectInputStream. The exception I'm getting is:

java.io.InvalidClassException: com.droplay.drawingonline.path.SerializedPath; unable to create instance at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at com.droplay.drawingonline.Session.run(Session.java:71) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedSerializationConstructorAccessor1.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.io.ObjectStreamClass.newInstance(Unknown Source) ... 5 more Caused by: java.lang.RuntimeException: Stub! at android.graphics.Path.(Path.java:24) ... 8 more

Now, to isolate the problem, I had tried creating a new class that doesn't have any members and doesn't extend anything and it did work. The server didn't throw any exception and it worked like a charm. I made sure the packages names are the same, the names of the classes are the same, the server uses the same SDK files as my Android project and the files' code in both the Android app and the Java server are EXACTLY the same, but I keep getting this exception. The app doesn't throw any exception. It sends the object just fine. Please, what's wrong with my code? Thank you for helping! :)

1

1 Answers

1
votes

Well I managed to solve it by sending the position of each click to the server, instead of a path class. But why didn't it work when I serialized it?