I am new to Java so this might be easy for some of you. I am doing a project where I have to read in a file and then do some stuff with that. I ran it and after about 30 seconds I got this error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at Proj4.main(Proj4.java:15)
My main method is:
Code:
public static void main(String[] args) throws Exception{
Vehicle[] List=new Vehicle[20];
File input= new File(args[0]);
Scanner ListInput=new Scanner(input);
int i=0;
for(i=0;ListInput.hasNext();i++){
if(i==List.length){
Vehicle[] temp=new Vehicle[List.length*2];
for(int j=0;j<List.length;j++){
temp[j]=List[j];
}
List=temp;
}
if(ListInput.equals("vehicle")){
List[i].setOwner(ListInput.nextLine());
List[i].setAdress(ListInput.nextLine());
List[i].setPhone(ListInput.nextLine());
List[i].seteMail(ListInput.next());
ListInput.nextLine();
continue;
}
if(ListInput.equals("car")){
List[i]=new Car();
List[i].setOwner(ListInput.nextLine());
List[i].setAdress(ListInput.nextLine());
List[i].setPhone(ListInput.nextLine());
List[i].seteMail(ListInput.next());
((Car)List[i]).setConvertable(Boolean.parseBoolean(ListInput.next()));
((Car)List[i]).setColor(ListInput.next());
ListInput.nextLine();
continue;
}
if(ListInput.equals("truck")){
List[i]=new Truck();
List[i].setOwner(ListInput.nextLine());
List[i].setAdress(ListInput.nextLine());
List[i].setPhone(ListInput.nextLine());
List[i].seteMail(ListInput.next());
((Truck)List[i]).setNumOfTons(ListInput.nextFloat());
((Truck)List[i]).setCost(ListInput.nextFloat());
ListInput.nextLine();
continue;
}
if(ListInput.equals("american car")){
List[i]=new AmericanCar();
List[i].setOwner(ListInput.nextLine());
List[i].setAdress(ListInput.nextLine());
List[i].setPhone(ListInput.nextLine());
List[i].seteMail(ListInput.next());
((AmericanCar)List[i]).setConvertable(ListInput.nextBoolean());
((AmericanCar)List[i]).setColor(ListInput.next());
((AmericanCar)List[i]).setMadeInDet(ListInput.nextBoolean());
((AmericanCar)List[i]).setUnionShop(ListInput.nextBoolean());
ListInput.nextLine();
continue;
}
if(ListInput.equals("foreign car")){
List[i]=new ForeignCar();
List[i].setOwner(ListInput.nextLine());
List[i].setAdress(ListInput.nextLine());
List[i].setPhone(ListInput.nextLine());
List[i].seteMail(ListInput.next());
((ForeignCar)List[i]).setConvertable(ListInput.nextBoolean());
((ForeignCar)List[i]).setColor(ListInput.next());
((ForeignCar)List[i]).setCountryMade(ListInput.nextLine());
((ForeignCar)List[i]).setImportDuty(ListInput.nextFloat());
ListInput.nextLine();
continue;
}
if (ListInput.equals("bicycle")){
List[i]=new Bicycle();
List[i].setOwner(ListInput.nextLine());
List[i].setAdress(ListInput.nextLine());
List[i].setPhone(ListInput.nextLine());
List[i].seteMail(ListInput.next());
((Bicycle)List[i]).setNumOfSpeeds(ListInput.nextInt());
I would really appreciate your help.