Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dnd not serializable

 
Brian Snyder2002
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
}
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic