Results 1 to 4 of 4
Thread: array index out of bounds
- 01-21-2012, 02:08 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 11
- Rep Power
- 0
array index out of bounds
Hi ppl heres my code and i keep getting array index out of bounds
private static int breakFast , nightSingle , nightPPS , nightSingleBreakFast , nightPPSBreakFast , discountRate , discountInterval ,
dinner;
private static File dir = new File("C:\\Mariette'sB&B");
private static File e = new File(dir , "prices.file");
private static BufferedReader in;
private static BufferedWriter out;
private static String [] prices = new String [7];
public static void readFile()throws FileNotFoundException , IOException{// readFile and add to array
if(e.exists()){
in = new BufferedReader(new FileReader(e));
String read = null;
int count = 0;
do{
read = in.readLine();
prices [count] = read;
count++;
}while(read != null);
in.close();
updatePrices();
}
else{
dir.mkdir();
e.createNewFile();
}
}
public static void writeFile()throws IOException{// writeFile
out = new BufferedWriter(new FileWriter(e));
for(int i = 0; i < prices.length ; i++){
out.write(prices[i]);
out.newLine();
}
out.flush();
out.close();
}
public static void updatePrices(){
breakFast = Integer.parseInt(prices[0]);
nightSingle = Integer.parseInt(prices[1]);
nightPPS = Integer.parseInt(prices[2]);
nightSingleBreakFast = Integer.parseInt(prices[3]);
nightPPSBreakFast = Integer.parseInt(prices[4]);
discountRate = Integer.parseInt(prices[5]);
discountInterval = Integer.parseInt(prices[6]);
dinner = Integer.parseInt(prices[7]);
}
and heres my file's content
36
272
195
300
230
15
5
80
i just cant get the error to go away ive tried resizing the array and then i get then i get numberformat exception but my array shud only contain the 8 elements in the file so i dont see why i need to make it bigger
- 01-21-2012, 02:23 PM #2
Member
- Join Date
- Jan 2012
- Posts
- 11
- Rep Power
- 0
Re: array index out of bounds
Ahhh i figured it out gosh im silly the file containing my information had a space behind a number lol human error i figured it out using a try statement and printing out my error
-
Re: array index out of bounds
Good for you, and thanks for posting your solution -- very thoughtful!
Please consider using [code] [/code] tags when next posting code here as it will make your posts easier to read. Best of luck!
- 01-21-2012, 02:27 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
array index out of bounds exception, AGAIN!
By samanyu in forum New To JavaReplies: 8Last Post: 06-08-2011, 11:27 AM -
having an array index out of bounds problem
By samanyu in forum New To JavaReplies: 18Last Post: 06-03-2011, 08:12 AM -
Array Index Out Of Bounds Exception
By manowar689 in forum New To JavaReplies: 3Last Post: 06-18-2010, 11:25 PM -
array Index out of Bounds exception== 0
By Allgorythm in forum New To JavaReplies: 6Last Post: 02-11-2010, 04:02 PM -
Array Index out of bounds
By leapinlizard in forum New To JavaReplies: 5Last Post: 04-29-2009, 05:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks