• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree in Java 1.2 versus Java 1.4  RSS feed

 
Bucky Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a project here at work that I've inherited from someone else. The problem I'm having is as follows:
1) Get rid of all the .class files and compile using Java 1.2. No errors.
2) Run the application using Java 1.2. The JTree code works just fine, no problems.
3) Run the application using Java 1.4. Everything works EXCEPT when a node is modified in the JTree it disappears from the tree!! Yep, gone, never to return. This is bad.
4) Get rid of all the .class files. Re-compile using Java 1.4. No errors.
5) Run the application using Java 1.4. I get the same results as in step 3. This is bad.
At work, I am under strict orders to get the application working under Java 1.4. Period. However, the JTree doesn't work right under 1.4, but DOES under 1.2. Any ideas? Thanks in advance.
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not aware of any difference using JTree between 1.2 and 1.4. I asked Spikes Magic 8-Ball what the problem with your program was, and it said "Concentrate and Ask Again". Sounds like it needs some more information. If I were you I'd use the graphical debugger in my IDE (or JSwat if you don't have one) and trace through the process of updating a node. If that doesn't make the problem obvious, I'd ask the group again, including the relevant that gets executed when updating a node. Without source it's back to Spike's Magic 8-Ball.
[ October 24, 2003: Message edited by: Joe Ess ]
 
Bucky Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe, Spikes Magic 8 ball really helped me out a lot, thanks..........NOT.
When running in Java 1.4, the problem is occurring with a DefaultTreeModel object. Specifically, when calling the method removeNodeFromParent. And yes, the passed in node to this method is good, no need to refer to the 8 ball. The exception that occurs with Java 1.4 is a NullPointerException. I am under the impression that possibly the exception is occuring inside of the method (IE: Sun's internal code specific to Java 1.4) since compiling and running the **EXACT SAME** code under Java 1.2 works just fine with no exceptions thrown whatsoever.
I have included a very short code snippet below.
.
.
.
EditorModule em = null;
DefaultMutableTreeNode mod_node = null;
DefaultMutableTreeNode par_node = null;
int index = 0;
DefaultTreeModel tree_model = null;
ModuleTree root_node = null;
try
{
em = (EditorModule)mod_sta.getTypeInfo();
// Get the tree model.
root_node = msg_mngr.root_tree;
tree_model = (DefaultTreeModel)root_node.getModel();
// Get the tree node of the module to be moved and also it's parent.
mod_node = getSTAModuleTreeNode( mod_sta );
par_node = (DefaultMutableTreeNode)mod_node.getParent();
// Get the index of the module node in the tree.
index = par_node.getIndex( mod_node );
if( index > 0 )
{
if((par_node != null) && (mod_node != null) && (tree_model != null))
{
// Remove the node from the tree.
tree_model.removeNodeFromParent( mod_node );
}
.
.
.
The code continues, but the line directly above is where the NullPointerException comes from. (IE: tree_model.removeNodeFromParent)
And yes, according to my Java debuggers, everything looks good. All the objects are initialized properly. Sorry for including just a tiny fraction of the code.
Just to reiterate: This works perfectly under Java 1.2, but gives NullPointerExceptions under Java 1.4.
Anyone else experience similar problems? If so, what was your workaround? Thanks in advance.
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bucky Lee:
Joe, Spikes Magic 8 ball really helped me out a lot, thanks..........NOT.

:roll: What I'm trying to get at is that you are leaving out some critical details. For example, in your first post you say that editing a node makes it disappear. In the code you posted, you are calling tree_model.removeNodeFromParent( mod_node );. Heck, it's even commented that it removes the node. Sounds like it is working correctly under 1.4 except for the null pointer exceptions. Unless you are leaving out some more details. Like what the method is supposed to be doing. I see a comment that says "Get the tree node of the module to be moved and also it's parent." So the code doesn't edit or remove a node, but move it? I can't tell from this snippet.
As for the Java 1.4 API, it is a simple matter to prove that it works fine, provided the correct information is passed to it:

Works great. Deletes nodes all day. Or at least 10 times.
My first impression is that the method getSTAModuleTreeNode( mod_sta ); is obtaining the tree node in a manner inconsistent with the 1.4 API, but somehow consistent with the 1.2. Look it over. If you use your debugger, when you look at a node, don't just look at the node, but examine it's parent pointer. I anticipate it is null somehow. Post getSTAModuleTreeNode() and the exception trace if you need more help.
 
Bucky Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe,
Please forgive me, I didn't mean to be rude the other day.
Also, I have not yet had the time to work anymore on this problem, but I will take a look at what you wrote in your previous post to see if I can implement that into the application. Thanks for taking the time to respond.
I'll let you know if I come across something that works.
Bucky
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!