Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 5th, 2008, 04:47 PM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 68 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 42 m 3 sec
Reputation Power: 4
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

Reply With Quote
  #2  
Old May 5th, 2008, 07:07 PM
spoon! spoon! is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 247 spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 8 h 15 m 23 sec
Reputation Power: 77
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

Reply With Quote
  #3  
Old May 5th, 2008, 07:55 PM
tfecw tfecw is online now
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Nov 2004
Location: Washington DC
Posts: 2,166 tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 6 Days 20 h 13 m 25 sec
Reputation Power: 410
Send a message via AIM to tfecw
Quote:
Originally Posted by GlobeTrotter
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..


snip
Caused by: java.io.NotSerializableException:
snip
at ChatHandler.broadcast(ChatHandler.java:67)
at ChatHandler.run(ChatHandler.java:34)


cheers
ciaran


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

Reply With Quote
  #4  
Old May 6th, 2008, 12:39 PM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 68 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 42 m 3 sec
Reputation Power: 4
Quote:
Originally Posted by tfecw
You're trying to serialize something that's not serializable. Looking at line 67 of ChatHandler is a good starting place


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

Reply With Quote
  #5  
Old May 8th, 2008, 09:36 PM
tfecw tfecw is online now
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Nov 2004
Location: Washington DC
Posts: 2,166 tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)tfecw User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 6 Days 20 h 13 m 25 sec
Reputation Power: 410
Send a message via AIM to tfecw
Quote:
Originally Posted by GlobeTrotter
here is my code.. like i said though it works though if i'm not using threads


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:
Caused by: java.io.NotSerializableException: java.io.DataInputStream


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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Java Thread Serializable Exception


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway