The moose likes Swing / AWT / SWT / JFace and the fly likes Dnd not serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Dnd not serializable" Watch "Dnd not serializable" New topic
Author

Dnd not serializable

Brian Snyder2002
Greenhorn

Joined: Jan 24, 2002
Posts: 11
I have a Transferable and Serializable object User. When I try to drop it on a registered Component I get the error:
java.io.NotSerializableException: java.io.CharArrayWriter
Why? I do a System.out.println(user.getUsername()); on the drag and it is a user. So I know it is of typwe user. I have also implemented the correct DataFlavor. Pleasee help!!!
[code]
public class User implements Transferable, Serializable, IXMLSerializeable, TreeNode{
.
.
.
// --------- Transferable --------------
public boolean isDataFlavorSupported(DataFlavor df) {
return df.equals(INFO_FLAVOR);
}
/** implements Transferable interface */
public Object getTransferData(DataFlavor df)
throws UnsupportedFlavorException {
if (df.equals(INFO_FLAVOR)) {
return this;
}
else throw new UnsupportedFlavorException(df);
}
/** implements Transferable interface */
public DataFlavor[] getTransferDataFlavors() {
return flavors;
}
}


Java Developer<br />SCJ2P
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
Look carefully at the error. It is a CharArrayWriter
that is not serializable. IO streams are not
serializable, which makes sense when you think
about it.
Declare the CharArrayWriter transient in the
User class. You will need to code to support
the dropped User needing a new Writer if you
try to write().
HTH,
Joe
Brian Snyder2002
Greenhorn

Joined: Jan 24, 2002
Posts: 11
Thanks Joe!
I actually fix the problem by creating a Wrapper class to hold my User class and future classes. On the drop, I get the singleton reference and extract the object that way. I don;t even have to use Transferable!!! Nice!!!
Many thanks!
 
IntelliJ Java IDE
 
subject: Dnd not serializable
 
Threads others viewed
Drag and Drop from JList to JTable.
BufferedImage to System Clipboard
DnD from Swing to Windows?
TransferHandler exception for Mac OS
Drag and Drop to Desktop Issue
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture