Thursday, December 4, 2008

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

Posted by Kian, Ting

I face this error when I am using the Java Excell API (http://jexcelapi.sourceforge.net), I got this when I try to open a work sheet via the WorkBook object.


I have seen in some article that to solve this simply turn up the Java Heap Size, and the method to do so is :- 

You can increase memory(heap size) by running java by including these parameters

-Xms[initial heap size] -Xmx[maximum heap size]

For example, set initial heap size to 128m and maximum to 256m.

java -Xms128m -Xmx256m

In NetBeans, simply goes to Project Properties –> Run.
Then you can add these parameters in VM Options.

In Eclipse you can set the Java Heap size via you just need to go to project settings, go under the run & debug setting, choose the existing setting to edit.

Then click on the argument tab when prompted a Properties dialog box, later click on the variables button under the VM arguments.

You will be prompted with another dialog box to select a variable, try select the "Xms" and "Xmx" variable, if they dont exists, then you have to create these new variables and add it in to the VM setting, and now you cant start to run your application.


0 comments:

Post a Comment