Skip to content
Advertisement

java.lang.OutOfMemoryError: Java heap space in allocating array size

I am doing very small program in java using Eclipse Kepler IDE.

I am allocating the size of the array at run time using the following statement.

JavaScript

so as per my knowledge the java program runs with some of its own heap space like 32 MB.

And for my program i think this space is enough.

I just given the value sizeRow=3 and sizeColumn=3 at runtime.

And when i pressed enter it gives the following Exception java.lang.OutOfMemoryError: Java heap space

I put this question to understand why it happens and how we can handle it?

I already read the following link.

java.lang.OutOfMemoryError: Java heap space

How to deal with “java.lang.OutOfMemoryError: Java heap space” error (64MB heap size)

EDIT:1

JavaScript

In my case i am calling these method only once.

Advertisement

Answer

The problems is here:

JavaScript

This would read a binary value from your input which would be like 2323827382 for your entered “1251” causing the OOM.

Try to use Scanner to read your integers like this:

JavaScript
Advertisement