• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with stringbuffer append method  RSS feed

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the following code which always gives me java heap space error because of line number 65 due to string buffer append method in this line, I don't know why?
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:i have the following code

Which does what exactly? It would appear to be some sort of RPN generator but, Mohamad, you cannot simply hand us 125 lines of undocumented code and expect us to know what you're trying to do. It also appears to rely heavily on the correctness of the list from your other thread which, at last reading, I would be very loath to assume.

However, at a cursory glance, I'd say that that block of code is missing a few "else"s.

Winston
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It convert from infix to postfix. I don't want to modify it. just I am asking about line 65 which has string buffer append method which always the error of java heap space is because of it
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:It convert from infix to postfix. I don't want to modify it. just I am asking about line 65 which has string buffer append method which always the error of java heap space is because of it

No it doesn't. If the statement compiles, then it will work, so something ELSE is causing your error; and the underlying cause is probably miles from that actual statement.

About the only thing I can tell you is that for some reason (and I've already given you one possibility) you have a never-ending loop somewhere, but until you're prepared to explain to us WHAT this code is supposed to do, in detail, there doesn't seem to be much point in spending a lot of time on it.

Winston
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first, I am sorry for wasting your time. here are my codes if you could help me. and In mean while, I am searching for the non ending loop as you said. those codes are supposed to convert from infix to postfix based on other three codes to push and remove elements from the stack with LIFO order and the other codes are




and the exception code
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:first, I am sorry for wasting your time. here are my codes if you could help me. and In mean while, I am searching for the non ending loop as you said. those codes are supposed to convert from infix to postfix based on other three codes to push and remove elements from the stack with LIFO order...

Yes, but how? Are you trying, for example, to implement a shunting yard algorithm? Because that's a fairly standard approach to the problem. However, your code doesn't look right because those 'if's aren't exclusive.

For example: you check if c is '(', and then later on check if it's ')', which AFAICS simply isn't possible.

I hate to say, but you're hamstringing yourself by:
(a) Not writing down the exact procedure in English (or your native language).
(b) Insisting on using home-grown classes (eg, stack and OrderedList) to do the stuff, when I'm not at all convinced that the latter one actually works (I haven't looked too closely at the first). Java already has classes for both that do work, so my advice would be to get the algorithm working with them before you try plugging in your hand-rolled stuff.

Otherwise, I'm afraid there are simply too many possibilities for what might be wrong to give much advice.

Winston
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as you said one major problem is non proper while loop which I solved it. the problem now is in the precedence of the operators which give me in logic error
here is my code of operators precedence
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:as you said one major problem is non proper while loop which I solved it. the problem now is in the precedence of the operators which give me in logic error...

Mohamad,

I really don't know how to say this without being blunt: You are going about this ass-backwards.

You are writing scads of code (without proper testing, I suspect), expecting it to work, and then coming to us when you run into problems.
This is not the way to program.

I understand that you're just dying to write Java code, but just ploughing ahead without some methodology is not how you learn, and is likely to leave you very frustrated. It also expects us to step into the breech when there are so many possibilities for what MIGHT have gone wrong that we're at a huge disadvantage.

StopCoding (and really READ that link).

Also: Did you read about the shunting yard algorithm? This is the standard way to convert infix to postfix, but you need to understand it before you write one more line of Java.

Winston
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for not being blunt with me (: . I red the link of stop coding and get a paper and pencil and found the solution. thanks again
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what was the error and its solution?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:I red the link of stop coding and get a paper and pencil and found the solution. thanks again

You're welcome. And I hope you remember the lesson, because it will (hopefully) serve you well.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!