2010-11-27 111 views
0
-(void)loadquestion { 
NSBundle *bundle = [NSBundle mainBundle]; 
NSString *textfilePath = [bundle pathForResource:@"MathPSLE" ofType:@"txt"]; 
NSString *fileContents = [NSString stringWithContentsOfFile:textfilePath encoding:NSUTF8StringEncoding error:nil]; 
NSArray *quizArray = [[NSArray alloc] initWithArray:[fileContents componentsSeparatedByString:@"\n"]]; 
theQuiz = quizArray; 
} 

*终止应用程序由于未捕获的异常 'NSRangeException',原因:' * - [NSCFArray objectAtIndex:]:索引(-4(或可能更大))超出边界(300)”***终止应用程序由于未捕获的异常 'NSRangeException',原因: '***


-(void)askquestion { 
QuestionNumber = QuestionNumber +1; 

NSInteger row = 0; 

if (QuestionNumber == 1) { 
    row = QuestionNumber -1; 
} 
else { 
    row = ((QuestionNumber -1 *6)); 
} 

NSString *selected = [theQuiz objectAtIndex:row]; 
NSString *activeQuestion = [[NSString alloc] initWithFormat:@"Question: %@",selected]; 
[ansButton1 setTitle:[theQuiz objectAtIndex:row+1] forState: UIControlStateNormal]; 
[ansButton2 setTitle:[theQuiz objectAtIndex:row+2] forState: UIControlStateNormal]; 
[ansButton3 setTitle:[theQuiz objectAtIndex:row+3] forState: UIControlStateNormal]; 
[ansButton4 setTitle:[theQuiz objectAtIndex:row+4] forState: UIControlStateNormal]; 
rightAnswer = [[theQuiz objectAtIndex:row+5]intValue]; 

questionLabel.text = activeQuestion; 

[selected release]; 
[activeQuestion release]; 
} 

-(IBAction)next_Button { 
[self askquestion]; 
} 

肯定的。当我插入断点。错误信息在这里。

+0

你确定'loadquestion`方法是错误的来源吗? – dreamlax 2010-11-27 03:00:28

+0

我同意梦幻,我没有看到它发生在那里。 – 2010-11-27 03:25:47

回答

1

从您的其他代码段中可以看出,该错误位于[theQuiz objectAtIndex:row+x]行中的某处。

看起来好像您在文件中的问题数量可能与代码认为它的最大问题数量不符。

另一件要看的事情是r ow = ((QuestionNumber -1 *6)) ..你确定这不是消极吗?

相关问题