• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with stringbuffer append method

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what was the error and its solution?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic