1

I found many post on this but nothing works. I am really desperate...

The root of the problem is that I want to send a custom object(lets call it PolylineAdapter) from a Java server(the Master) to the Android client application. The fact is that if I create two identical PolylineAdapter classes(one on the server and one on the client), I get ClassNotFoundException(when I read the object from the Socket’s ObjectInputStream on the client side) which is rational given the fact that these are two separate classes.

To solve this problem I am considering of packaging the PolylineAdapter class in a jar which I can then import in my Android project and in my server project. The jar will contain exactly the same PolylineAdapter class on both project, so I will not get the exception.

The problem is that the Android Studio won’t recognize my PolylineAdapter class. I tried importing my jar as jar dependency in both IDEA(by JetBrains) and Eclipse and worked well, but Android Studio doesn’t recognize it when I write a statement in the editor. I tried every answer I found(Add as Library, create new module etc.) but nothing worked.

  • "The jar will contain exactly the same PolylineAdapter class on both project, so I will not get the exception" -- but you might get other exceptions. Do not assume that serialization is necessarily the same between virtual machines. Use a platform-neutral data format: JSON, XML, protobuf, Thrift, etc. "I tried every answer I found" -- https://stackoverflow.com/a/16628496/115145 – CommonsWare Jun 14 '17 at 21:06
  • I tried that answer too. Do you mean that a class might be serialized differently on the android and on the server? – Mitromaras Giannis Jun 14 '17 at 21:13
  • "I tried that answer too" -- then edit your question and provide a [mcve], which would include the `build.gradle` file with the `compile` statement to pull in that JAR. "Do you mean that a class might be serialized differently on the android and on the server?" -- yes. – CommonsWare Jun 14 '17 at 21:18

0 Answers0