views:

305

answers:

2

---sorry i dont want my code to be here anymore until the deadline is over---

A: 
BlairHippo
+5  A: 

The problem is that your class MyPostfixMachine has a private field MyPostfixMachine mpm which is initialized with a new MyPostfixMachine. Since this new MyPostfixMachine also has a private field MyPostfixMachine mpm which is initialized with a new MyPostfixMachine... you get it. :) This goes on and on forever (or until your stack is full).

Here is the problematic piece of code:

public class MyPostfixMachine implements PostfixMachineInterface {

    MyMathOperations mmo = new MyMathOperations();
    MyPostfixMachine mpm = new MyPostfixMachine(); // problem is here

    // ...
}

I think you can simply remove the private field mpm. Just call the methods on the current instance. So instead of:

if (mpm.isParsableToDouble(String.valueOf(q.remove()))) {...}

you can simply write:

if (isParsableToDouble(String.valueOf(q.remove()))) {...}

or (equivallent but more explicit):

if (this.isParsableToDouble(String.valueOf(q.remove()))) {...}

Anyway, just remove the private field mpm and the StackOverflowException should be gone.

stmax
Nice catch! Glad I put that "Unless I'm missing something" piece of butt-covering in my own answer. :-)
BlairHippo
Oh my god that is the single piece of code which i would have never suspected would cause the error, thank you so much!i can now continue with my assignment. Again thank you.
JIM