Eclipse Kepler IDE를 사용하여 Java에서 매우 작은 프로그램을 수행하고 있습니다.java.lang.OutOfMemoryError : 배열 크기 할당시 Java 힙 공간
다음 문을 사용하여 런타임에 배열의 크기를 할당합니다.
unSortedArray = new int[sizeRow][sizeColumn];
내 지식에 따라 Java 프로그램은 32MB와 같은 일부 자체 힙 공간에서 실행됩니다.
내 프로그램에 대해서는이 공간으로 충분하다고 생각합니다.
런타임에 값 sizeRow=3
및 sizeColumn=3
을 방금 지정했습니다.
java.lang.OutOfMemoryError: Java heap space
다음과 같은 예외를 준다?
나는 이미 다음 링크를 읽었습니다.
java.lang.OutOfMemoryError: Java heap space
How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size)
편집 : 내 경우 1
public class ArraySort
{
private int[][] unSortedArray;
private int sizeColumn, sizeRow;
private final DataInputStream dataInputStream = new DataInputStream(
System.in);
public boolean getArraySize() throws IOException
{
try
{
System.out.print("Enter the size of the row:");
sizeRow = (dataInputStream.readInt());
System.out.print("Enter the size of the column:");
sizeColumn = dataInputStream.readInt();
return false;
}
catch (NumberFormatException e)
{
System.out.println("Enter valid value for size:");
}
return true;
}
public boolean getArrayElement() throws IOException
{
unSortedArray = new int[sizeRow][sizeColumn];
for (int i = 0; i < sizeRow; i++)
{
for (int j = 0; j < sizeColumn; j++)
{
try
{
System.out.println("Enter Element [" + i + "," + j + "]");
unSortedArray[i][j] = dataInputStream.readInt();
}
catch (NumberFormatException ne)
{
System.out
.println("Enter proper Numeric value for Array Element");
return true;
}
}
}
return false;
}
}
public class ArraySortProgram
{
public static void main(String[] args) throws IOException
{
ArraySort arraySort = new ArraySort();
arraySort.getArraySize();
arraySort.getArrayElement();
}
}
내가 한 번만이 메소드를 호출하고 있습니다. 당신이 우리를 보여으로
오류 이런 종류는 처리 할 수없는,하지만 당신은 한 번에 전체 코드를 게시 할 수있는 나는, 이런 일이 왜 확실하지 않다 :
은 다음과 같이 당신의 정수를 읽을
Scanner
를 사용해보십시오. – Batty그래서'int's의 3x3 배열을 만들고 OOME을 얻습니다. 정말? – Vidya
예. 지구 주위를 돌고있는 태양처럼 보입니다 : P하지만 약간의 포획이 있어야합니다 !! – Batty