out of bounds exception
out of bounds exception
- Subject: out of bounds exception
- From: Daniel Child <email@hidden>
- Date: Tue, 08 Feb 2005 01:01:45 -1000
Thanks again to previous senders correcting my stupid newbie array error.
Now I am getting an out of bounds exception I can't account for. The error reads:
2005-02-08 00:56:13.406 BpmfTable[1289] An uncaught exception was raised
2005-02-08 00:56:13.407 BpmfTable[1289] *** -[NSCFArray objectAtIndex:]: index (2) beyond bounds (1)
2005-02-08 00:56:13.408 BpmfTable[1289] *** Uncaught exception: <NSRangeException> *** -[NSCFArray objectAtIndex:]: index (2) beyond bounds (1)
What is strange is that this error is generated AFTER correctly parsing and reading in all the data. I checked the datafile itself, and tried adding another newline to make sure the last record was included in linesOfData, but that proved unnecessary since it was already read in (NSLogs proved that).
Does anyone know why this kind of error would come up? I thought enumerators would stop when they reached the end. Thanks. Code to follow....
int count = 0;
NSMutableArray *syllables = [NSMutableArray array];
Syllable *theSyllable = [Syllable alloc];
NSString *line;
NSString *fileContents = [NSString stringWithContentsOfFile:
[@"~/Desktop/wgbppy.txt" stringByExpandingTildeInPath]];
NSArray *linesOfData = [fileContents componentsSeparatedByString:@"\n"];
NSEnumerator *arrayEnum = [linesOfData objectEnumerator];
NSLog(@"linesOfData has %i lines", [linesOfData count]);
while (line = [arrayEnum nextObject]) {
NSArray *threeSyllables = [line componentsSeparatedByString:@"\t"];
[theSyllable initWithPinyin: [threeSyllables objectAtIndex: 2]
bopomofo: [threeSyllables objectAtIndex: 1]
wadegiles: [threeSyllables objectAtIndex: 0]];
if (theSyllable != nil) {
[syllables addObject: theSyllable];
[theSyllable release];
}
count++;
} _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden