While i try to run TestRun, i got following errors. I tried a lot but i could not find it out. Help me! I got Out of memory error Java Heap. Running the following code also takes more time to run, at last it shows error as given below. How to make this code right? Debugging this is very difficult for me.Exception in thread "main" java.lang.OutOfMemoryError: Java heap space.
package website;
import java.util.ArrayList;
import Combination.averageM;
import Combination.boatandstreamM;
import Combination.fractionsM;
import Combination.interestM;
import Combination.measurementM;
import Combination.numberM;
import Combination.percentageM;
import Combination.profitandlossM;
import Combination.simplificationM;
import Combination.timeanddistanceM;
import Combination.timeandwM;
public class ArrayOfSums {
ArrayList<sums> als;
String Q, A, scale, finalvalue;
double fv;
NewOptions pencil = new NewOptions();
sums sumsObj;
public ArrayList<sums> giveArrayOfSums(int x) {
als = new ArrayList<sums>();
int n = 0;
switch (x) {
case 1:
simplificationM pen = new simplificationM();
while (n <= 19) {
pen.simplificationM();
pencil.optionsCreator(pen.fv, pen.scale);
sumsObj = new sums(pen.Q, pen.A, pen.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 2:
numberM pen1 = new numberM();
while (n <= 19) {
pen1.numberM();
pencil.optionsCreator(pen1.fv, pen1.scale);
sumsObj = new sums(pen1.Q, pen1.A, pen1.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 3:
percentageM pen2 = new percentageM();
while (n <= 19) {
pen2.percentageM();
pencil.optionsCreator(pen2.fv, pen2.scale);
sumsObj = new sums(pen2.Q, pen2.A, pen2.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 4:
numberM pen3 = new numberM();
while (n <= 19) {
pen3.numberM();
pencil.optionsCreator(pen3.fv, pen3.scale);
sumsObj = new sums(pen3.Q, pen3.A, pen3.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 5:
fractionsM pen4 = new fractionsM();
while (n <= 19) {
pen4.fractionsM();
pencil.optionsCreator(pen4.fv, pen4.scale);
sumsObj = new sums(pen4.Q, pen4.A, pen4.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 6:
profitandlossM pen5 = new profitandlossM();
while (n <= 19) {
pen5.profitandlossM();
pencil.optionsCreator(pen5.fv, pen5.scale);
sumsObj = new sums(pen5.Q, pen5.A, pen5.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 7:
averageM pen6 = new averageM();
while (n <= 19) {
pen6.averageM();
pencil.optionsCreator(pen6.fv, pen6.scale);
sumsObj = new sums(pen6.Q, pen6.A, pen6.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 8:
timeandwM pen7 = new timeandwM();
while (n <= 19) {
pen7.timeandwM();
pencil.optionsCreator(pen7.fv, pen7.scale);
sumsObj = new sums(pen7.Q, pen7.A, pen7.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 9:
timeanddistanceM pen8 = new timeanddistanceM();
while (n <= 19) {
pen8.timeanddistanceM();
pencil.optionsCreator(pen8.fv, pen8.scale);
sumsObj = new sums(pen8.Q, pen8.A, pen8.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 10:
boatandstreamM pen9 = new boatandstreamM();
while (n <= 19) {
pen9.boatandstreamM();
pencil.optionsCreator(pen9.fv, pen9.scale);
sumsObj = new sums(pen9.Q, pen9.A, pen9.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3, pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 11:
interestM pen11 = new interestM();
while (n <= 19) {
pen11.interestM();
pencil.optionsCreator(pen11.fv, pen11.scale);
sumsObj = new sums(pen11.Q, pen11.A, pen11.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3,
pencil.jRadioButton4);
als.add(sumsObj);
}
break;
case 12:
measurementM pen12 = new measurementM();
while (n <= 19) {
pen12.measurementM();
pencil.optionsCreator(pen12.fv, pen12.scale);
sumsObj = new sums(pen12.Q, pen12.A, pen12.finalvalue, pencil.jRadioButton1, pencil.jRadioButton2, pencil.jRadioButton3,
pencil.jRadioButton4);
als.add(sumsObj);
}
break;
}
return als;
}
}
Class Sum:
package website;
public class sums {
public String Question, Answer, Finalvalue, P1, P2, P3, P4;
public int choosenOption;
public sums(String Q, String A, String finalvalue, String p1, String p2, String p3, String p4) {
Question = Q;
Answer = A;
Finalvalue = finalvalue;
P1 = p1;
P2 = p2;
P3 = p3;
P4 = p4;
}
public void setChoosen(int n) {
choosenOption = n;
}
}
Class TestRun:
package website;
import java.util.ArrayList;
public class TestRun {
/**
* @param args
*/
public static void main(final String[] args) {
ArrayOfSums SumsTable = new ArrayOfSums();
//session.setAttribute("sumtin",SumsTable.giveArrayOfSums(8));
ArrayList<sums> SumsSet = (ArrayList<sums>) SumsTable.giveArrayOfSums(8);
sums gotSum = (sums) SumsSet.get(1);
System.out.println(gotSum.Question);
}
}