drag and drop NotSerializableException on unique node

6

6e

Please notice that my question is about a specific error, not drag and
drop. I followed the information on
http://www.javaworld.com/javaworld/javatips/jw-javatip97.html for drag
and drop.
For anyone not familiar with this it basically describes how to
properly implement transferable and serializable so that drag and drop
is possible on jtree's.

However my problem seems to occur on the second time that I drag and
drop an object. I use a unique node that is attached to a unique
jtable object ( I call this object TreeNodeTableLink). I do not
receive a program crashing error, but rather one that I have to catch,
and one that seems to cripple my jtree linked to my jtable.

Both my jtable and my node objects implement serializabe (as I
discovered was neccessary on http://www.devx.com/tips/Tip/13020 ).

The problem occurs in the public void drop(DropTargetDropEvent e)
function on this line:

//cast into appropriate data type
TreeNodeTableLink childInfo = (TreeNodeTableLink)
tr.getTransferData(tntlFlavor);

I catch the IOException and print a stack trace which pointed me to
this line. I'm pretty confused as to what the problem is, does anyone
have any ideas about how I may be able to correct this problem? Or has
anyone experienced this "error" before and successfully solved it? I
think Im losing it...

Thanks for your help!

----------code---------------
// DropTargetListener interface method - What we do when drag is
released
public void drop(DropTargetDropEvent e) {
System.out.println("TreeLinking : drop");
try {

Transferable tr = e.getTransferable();

//flavor not supported, reject drop
if (!tr.isDataFlavorSupported(TreeNodeTableLink.tntlFlavor)){
e.rejectDrop();
}
else{
System.out.println("Dataflavor Supported");
}

//cast into appropriate data type
TreeNodeTableLink childInfo = (TreeNodeTableLink)
tr.getTransferData(tntlFlavor);
//ERROR
 
M

mrandywarner

Depending on what your transfer object has references to, it may have a
reference to the TableModel, which in turn has a reference to the table
which will try to serialize the entire table and everything in it.
Have you tried using DataFlavor.javaJVMLocalObjectMimeType? You can
use the constructor, new
DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=" +
RepresentedClass.class.getName(), "Class Description"). This will
avoid serializing the object and just refer to the object in the local
jvm.
 
T

tiewknvc9

awesome, that solved that problem!

to sum up for anyone with a similar problem:
I had to alter my Dataflavor to:

Datflavor x = DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
";class=" + MyClass.class.getName(), "Class Description")

thanks again
 
R

Roedy Green

I catch the IOException and print a stack trace which pointed me to
this line.

You did not quote the error or stack trace. Usually an IOException
gives you a hint as to the trouble.


try stretching this code out like this:

TreeNodeTableLink childInfo = (TreeNodeTableLink)
tr.getTransferData(tntlFlavor);

System.out.println( tntlFlavor);
Object o = tr.getTransferData ( tntlFlavour );
Sytem.out.println( o.getClass() );
Sytem.out.println( o );
TreeNodeTableLink childInfo = (TreeNodeTableLink)o;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top