-1

I'm trying to send a few Objects around through java.net.Socket and java.net.ServerSocket by using an ObjectOutputStream and ObjectInputStream but I've come across an issue with that. The objects I'm trying to send aren't serializable. I've tried sending them as a String but it can't be cast. Any work-arounds for this issue?

EDIT:

I was looking through the StackTrace of the problem, and found that it's being thrown by JLabel. I thought that was odd, due to the fact that JLabel implements Serializable. But when I checked the JavaDocs through eclipse and came to the line where the error was being thrown by public boolean updateImage(ect..) and realized that it's due to Icon. Is there any way to avoid the issue?

TheNerdyCoder
  • 184
  • 1
  • 10
  • What type are the objects, and why aren't they serializable? – Matt Ball Apr 01 '13 at 23:36
  • @MattBall com.apple.laf.AquaInternalFrameUI. I'm trying to send JInternalFrames – TheNerdyCoder Apr 01 '13 at 23:37
  • 1
    How could something closely tied to the UI and hardware on one system possibly be reconstituted as a valid object on the remote system? If you want to accomplish something like this you need to make your own state-transport object that encapsulates whatever is meaningful and transportable about the object on the source, then on the destination system create a new object with the same state valid in that context. – Jim Garrison Apr 01 '13 at 23:49
  • Sounds like it would work, but could you repeat it once more? In English please. – TheNerdyCoder Apr 01 '13 at 23:53

2 Answers2

2

There is a loud warning in the Javadoc of every single Swing component about not serializing Swing components. Read it. What you should be doing is serializing the respective models.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I did read the JavaDocs and the only thing it has to say about Serialization is that serialized objects from swing won't be compatible with other Swing releases. – TheNerdyCoder Apr 02 '13 at 00:33
0

You need to implement the Serializable interface mate ;) Take a look here: http://docs.oracle.com/javase/1.5.0/docs/api/java/io/Serializable.html

You need to implement this interface on the class of the object you are trying to send via socket.

TiagoM
  • 3,458
  • 4
  • 42
  • 83
  • But what if the Object I'm trying to send can't be changed? I'm sending a JInternalFrame and the com.apple.laf.AquaInternalFrameUI$6$1 class keeps throwing the exception. – TheNerdyCoder Apr 01 '13 at 23:36
  • 1
    _why_ are you trying to send a UI component across a socket‽ – Matt Ball Apr 01 '13 at 23:37
  • you should not send via socket classes like that, GUI classes.. you should send information classes. made your own classes with the whole structure of the information. And on the other point of the socket, you cast to the object, and then you apply that information on the JInternalFrame, dont sen't the frame itself through the socket. – TiagoM Apr 01 '13 at 23:37
  • Because I was looking for a way to code a JInternalFrame in one app, use a class to send it, and then receive it in an OS mock application that a colleague wanted me to write. – TheNerdyCoder Apr 01 '13 at 23:38
  • Then what should I do? I can't really think of any other things that would allow to applications to communicate indirectly. – TheNerdyCoder Apr 01 '13 at 23:43
  • @MattBall I've found that the error is coming from Icon in the JLabel class. Perhaps that would shine some more light on the issue. – TheNerdyCoder Apr 02 '13 at 00:23