aspose file tools*
The moose likes Beginning Java and the fly likes getting stackOverFlowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting stackOverFlowError" Watch "getting stackOverFlowError" New topic
Author

getting stackOverFlowError

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
Hello, I've been working on an assignment that was due last week so right now I'm just trying to understand the concept of how to get this thing to work. I'm supposed to build a tree recursively and at the moment I'm getting an error when I use the build method that looks like this:

The error continues in ExprTree.java:176 more times than I'd like to count or paste into this thread.
Here is the code I currently am using to build the expression tree.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4492
    
    8

The usual cause of a StackOverflowError is that your code has gone into an infinite recursive loop.

Have another look at the line causing the problem. You're calling buildSub(p) within the buildSub() method - a recursive call. Now, recursion is fine, but you have to be sure that the recursive calls will end at some point. Here, you keep calling buildSub() with the same argument, and nothing else has changed that might mean that the recursion will stop. You call it before the value of i is changed, for example. So once the recursion has started, it will never stop.
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
It works! Thanks! Well it doesn't really work but it didn't give me the error lol. I only changed where i is incremented.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4492
    
    8

By the way - I'd recommend changing the name of that variable. i is fine as a variable name when you're talking about a simple local loop. But you're saving the value as part of the object's state, so you really ought to use something more meaningful - something that actually describes what it means.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting stackOverFlowError