This discussion is archived
2 Replies Latest reply: Jul 22, 2009 2:38 AM by 843807 RSS

java.lang.OutOfMemoryError: Java heap space

843807 Newbie
Currently Being Moderated
I have this method that causes me "java.lang.OutOfMemoryError: Java heap space" someone can help me to fix me this problem?
       
 public String readProperty() throws IOException {
            StringBuffer buffer = new StringBuffer();
            String line;

            try {

                while (true) {

                    line = readLine().trim();

                    if ((line.length() != 0) && (line.charAt(0) != '#')) {
                        if (line.endsWith("\\")) {
                            line = line.substring(0, line.length() - 1);
                            buffer.append(line);
                        } else {
                            buffer.append(line);
                            break;
                        }
                    }
                }

            } catch (NullPointerException e) {
                return null;
            }

            return buffer.toString();
        }


thanks:)
    }
  • 1. Re: java.lang.OutOfMemoryError: Java heap space
    843807 Newbie
    Currently Being Moderated
    Hi, I think I can't help you, because I can't even compile the method you have posted. The problem is at the line, where it is written:
    line = readLine().trim();
    And it tells that the readLine() method is undefined (which is in fact true). By the way, by just looking at the code I do not understand why are you catching a NullPointerException and what causes it to be thrown (maybe the unknown readLine() method). Still there are more information required to solve your problem.
  • 2. Re: java.lang.OutOfMemoryError: Java heap space
    843807 Newbie
    Currently Being Moderated
    Hi,

    Is your problem solved ? Which server are you using ?
    Please change the "Sun JVM memory allocation pool parameters" in the script which is used to run the server. (For eg, run.bat file in JBoss)
    This will increase the memory space for running your application and OutOfMemoryException won't come.