2010-11-27 60 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)) ..你確定這不是消極嗎?

相關問題