I got runtime error as "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ". How can I solve this problem? Can anyone explain me why this problem occurs? Thanks in advance.
Recursion causes StackOverflow, not often OutOfMemory
You're probably trying to read in some very large file or otherwise reserving a lot of memory.
Figure out where you are doing that and try to find a way around it.
Look to see if you're creating lots of new objects. Memory Exceptions ocure when your java application uses all of its allowed memory. I believe the default setting is 64megs. My guess is that inside a loop (if, while, or a recursive loop) there are new objects being created. While this isn't bad, it could be the source of the problem.
Unless there's a definite limit to the amount of memory the application will claim (so no errors or unforeseen conditions causing infinite loops for example) that will only delay the inevitable
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.