Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java thread: Crazy!! Tree object Casting... Error


Message #1 by "Kharsim Al Mosawi" <kharsim@y...> on Sat, 30 Jun 2001 21:34:24
I've created a Jtree, consisting of objects of type (String x, String y, 
String z), When i rename a leaf id like the first String "x" in the object 
to change accordingly and the rest to remain the same...

I've used a TreeModelListener with the treeNodesChanged methods to listen 
for a rename and the below code to change it, But i keep getting the 
following:-
java.lang.ClassCastException: java.lang.String

// Code
DefaultMutableTreeNode node = (DefaultMutableTreeNode) 
tree.getLastSelectedPathComponent();
MObject obj = (MObject) node.getUserObject(); //error
node.setUserObject(new MObject (obj.x, obj.y, obj.z)); 

the casting works perfectly in other sections of the code just not here. 
please help Thx

  Return to Index