1

Ok so, I'm trying to create a browser that connects to a server and when the user enters in a url the browser sends that url to the server. The server then opens the url in a JEditorPane then uses the getDocument() method attempts to send that document through a ObjectOutputStream back to the client. Unfortunately I haven't been able to figure this one out, is it not possible to send a Document through an objectoutputstream or what am I doing wrong?

Here's the code that I'm using:

Method that sets page and gets the Document:

url = (String) input.readObject();

window.setPage(url);
doc = window.getDocument();

sendDoc(doc);

Method that sends the Document through objectoutputstream:

try {

    output.writeObject(doc); // no compiling errors...
    output.flush();

} catch (Exception e) { }

Error that I get:

java.io.WriteAbortedException: writing aborted;
java.io.NotSerializableException:
javax.swing.text.html.CSS$Value is not serializable as a value in an AttributeSet

...

at DawgsCodeBrowser.whileConnected(DawgsCodeBrowser.java:101)
at DawgsCodeBrowser.Run(DawgsCodeBrowser.java:71)
at StartBrowser.main(StartBrowser.java:8)
Caused by: java.io.NotSerializableException:
javax.swing.text.html.CSS$Value is not serializable as a value in an AttributeSet

...

at DawgsCodeServer.sendDoc(DawgsCodeServer.java:154)
at DawgsCodeServer.whileConnected(DawgsCodeServer.java:100)
at DawgsCodeServer.Run(DawgsCodeServer.java:59)
at StartServer.main(StartServer.java:11)

sorry for long error message, I took out some of it so it wouldnt be as long...

lynks
  • 5,599
  • 6
  • 23
  • 42
DawgsCode
  • 19
  • 1
  • The object that you're trying to write does implement the `serializable` interface. First line in the error message. What class is `doc`? – Mike G Dec 07 '12 at 21:52

1 Answers1

2

Says so right here:

Caused by: java.io.NotSerializableException: javax.swing.text.html.CSS$Value is not serializable as a value in an AttributeSet 

This internal CSS$Value class is killing you, and there's probably not a whole lot you can do about it.

Rather you need to question why sending the Document is better than sending the actual raw HTML in this case.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • Why is it trying to serialize `CSS.Value` in the first place? Isn't it sufficient to serialize `CSS`? `CSS` is a `Serializable`. – reprogrammer Dec 07 '12 at 22:01
  • Because the data structure is referring to a CSS$Value internally. The java serializer is just walking the objects, and it stumbled upon an instance of CSS$Value, which obviously is not serializable. Once found, it ruins the whole party. – Will Hartung Dec 07 '12 at 22:28