Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-03-2009, 11:07 PM   PM User | #1
grifan526
New to the CF scene

 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
grifan526 is an unknown quantity at this point
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.
grifan526 is offline   Reply With Quote
Old 03-04-2009, 07:56 AM   PM User | #2
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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
BubikolRamios is offline   Reply With Quote
Old 03-04-2009, 12:12 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:37 AM.


Advertisement
Log in to turn off these ads.