我的代码出于某种原因给我一个内存不足的错误。我已经尝试增加分配给ecplise的内存量,但似乎什么也没做。这是我的代码,错误来自:
public static ArrayList<Integer> getSortedEndPoints(ArrayList<Interval>leftSortedIntervals, ArrayList<Interval> rightSortedIntervals) {
int left;
int size = leftSortedIntervals.size();
Interval interval;
ArrayList <Integer> sortedEndPoints = new ArrayList<Integer>();
for (int i = 0; i < size; i++){
interval = leftSortedIntervals.get(i);
left = interval.leftEndPoint;
//System.out.println("Left Endpoint at " + i + "is : " + left);
if (sortedEndPoints.size() == 0){
//System.out.println("Entered size 0");
sortedEndPoints.add(left);
} else if (searchForDuplicate(sortedEndPoints, left) == false){
//System.out.println("Search For Duplicates is False");
sortedEndPoints.add(left);
}
}
System.out.println("Sorted End Points after left search : " + sortedEndPoints);
int right;
size = rightSortedIntervals.size();
for (int i = 0; i < size; i++){
interval = rightSortedIntervals.get(i);
right = interval.rightEndPoint;
if (sortedEndPoints.size() == 0){
sortedEndPoints.add(right);
} else if (searchForDuplicate(sortedEndPoints, right) == false){
System.out.println("Search For Duplicates is False");
size = sortedEndPoints.size()-1;
System.out.println("Size= " + size);
System.out.println("sortedEndPoints.get(size) " + sortedEndPoints.get(size));
if (right > sortedEndPoints.get(size)){
sortedEndPoints.add(right);
} else {
for (int t = 0; t < sortedEndPoints.size(); t++){
if (right < sortedEndPoints.get(t)){
sortedEndPoints.add(t, right);
}
}
}
}
}
System.out.println("Sorted End Points after right search : " + sortedEndPoints);
return sortedEndPoints;
}
private static boolean searchForDuplicate(ArrayList<Integer>sortedEndPoints, int left){
for (int track = 0; track < sortedEndPoints.size(); track++){
if (left == sortedEndPoints.get(track)){
return true;
}
}
return false;
}
这是我得到的错误
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
at java.util.ArrayList.add(ArrayList.java:370)
at structures.Sorter.getSortedEndPoints(Sorter.java:148)
at structures.IntervalTree.<init>(IntervalTree.java:39)
at apps.IntervalTreeDriver.main(IntervalTreeDriver.java:19)
我不知道现在要做什么......
答案 0 :(得分:0)
eclipse.ini中的值会更改Eclipse自身使用的内存,而不是运行程序时使用的内存。
要更改程序运行时所使用的程序,请打开&#39;运行&gt;运行配置&#39;对话。在“Java程序”中找到您的程序&#39;部分。关于&#39;参数&#39;选项卡在“VM参数”中添加内存参数&#39;部分。