Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Out of Memory Error

    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.

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    at tomcat folder look for catalina.bat
    find something like that, and edit, I think you have smaller numbers, restart tomcat, that should help.
    Code:
    set JAVA_OPTS  ............  -Xms256m -Xmx1024m

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by BubikolRamios View Post
    at tomcat folder look for catalina.bat
    find something like that, and edit, I think you have smaller numbers, restart tomcat, that should help.
    Code:
    set JAVA_OPTS  ............  -Xms256m -Xmx1024m
    There is no indication that this is a JSP page.
    Code:
    for(i=0;ListInput.hasNext();i++){
    Looks to me like you're outer loop has no ending condition. Change this to an while(ListInput.hasNext()). You should consider using a buffered reader stream since you're dealing with a file.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •