|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Java Thread Serializable Exception
ok i'v been stuck on this error all over the weekend. any ideas before i proceed with a whole other route.. i'm trying to write the object but it bombs out. i think the problem is something to do with me using threads cos it works fine without them..
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException : java.io.DataInputStream at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.defaultReadFields(Unknown Source) at java.io.ObjectInputStream.readSerialData(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readArray(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.defaultReadFields(Unknown Source) at java.io.ObjectInputStream.readSerialData(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at Gui.run(Gui.java:189) at java.lang.Thread.run(Unknown Source) Caused by: java.io.NotSerializableException: java.io.DataInputStream at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) at java.io.ObjectOutputStream.writeSerialData(Unknown Source) at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.writeArray(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) at java.io.ObjectOutputStream.defaultWriteObject(Unknown Source) at java.util.Vector.writeObject(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source) at java.io.ObjectOutputStream.writeSerialData(Unknown Source) at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.writeObject(Unknown Source) at ChatHandler.broadcast(ChatHandler.java:67) at ChatHandler.run(ChatHandler.java:34) cheers ciaran |
|
#2
|
|||
|
|||
|
you should post your code. without it there is no clue what is going on; but generally, it says that something is not serializable, so you are probably trying to serialize an object whose class is not serializable
|
|
#3
|
|||
|
|||
|
Quote:
You're trying to serialize something that's not serializable. Looking at line 67 of ChatHandler is a good starting place
__________________
Open for extension, closed for modification |
|
#4
|
|||
|
|||
|
Quote:
here is my code.. like i said though it works though if i'm not using threads Code:
import java.net.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class ChatHandler extends Thread implements Serializable
{
protected Socket s;
protected DataInputStream i;
protected DataOutputStream o;
protected ObjectOutputStream vectorObj;
public ChatHandler (Socket s) throws IOException
{
this.s = s;
i = new DataInputStream (new BufferedInputStream (s.getInputStream ()));
o = new DataOutputStream (new BufferedOutputStream (s.getOutputStream ()));
vectorObj = new ObjectOutputStream(s.getOutputStream());
}
protected static Vector handlers = new Vector ();
public void run ()
{
String name = s.getInetAddress().toString ();
try
{
broadcast(name + " has joined.");
handlers.addElement(this);
while (true)
{
String msg = i.readUTF();
broadcast (name + " - " + msg);
}
}
catch (IOException ex)
{
ex.printStackTrace ();
}
finally
{
handlers.removeElement (this);
broadcast (name + " has left.");
try
{
s.close ();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
protected static void broadcast (String message)
{
synchronized (handlers)
{
Enumeration e = handlers.elements ();
while (e.hasMoreElements ())
{
ChatHandler c = (ChatHandler) e.nextElement ();
try
{
c.vectorObj.writeObject(handlers);
}
catch (Exception ex)
{
c.stop();
}
}
}
}
cheers ciaran |
|
#5
|
||||
|
||||
|
Quote:
Threads have nothing to do with it. At line 67, you are trying to serialize "handlers" handlers is a Vector (ArrayList should be used instead of Vectors) Vectors are serializeable so they wouldn't cause the exception. Something in them might though! At line 30 you are adding (this) to the vector. A quick look at the class members leads us to the culprit(s) DataStreamInput is not serializable. Which, by no coincidence is what the stack trace says... Quote:
I'm not really sure what you're trying to do in your program so i'm not sure what direction to point you, but you should know why the error is being caused now. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Java Thread Serializable Exception |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|