什么是“应用程序终止”的错误?

问题描述:

错误什么是“应用程序终止”的错误?

*终止应用程序由于未捕获的异常 'NSRangeException',原因: '* - [__ NSArrayM objectAtIndex:]:索引1超出范围[0 .. 0]'

这里我代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"AartiTableViewCell"; 
    AartiTableViewCell *cell = (AartiTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AartiTableViewCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
     cell.btnFav.userInteractionEnabled=YES;    
    } 

    NSString *strfavarry = [NSString stringWithFormat:@"SELECT Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]]; 
    FavTitle = [FavData lookupAllForSQL:strfavarry]; 

    cell.selectionStyle=UITableViewCellSelectionStyleNone; 
    cell.index = indexPath.row; 
    cell.btnFav.tag=indexPath.row; 
    [cell.btnFav setBackgroundImage:[UIImage imageNamed:@"unfav.png"] forState:UIControlStateNormal]; 
    [cell.btnFav addTarget:self action:@selector(handleFavouriteButton:) forControlEvents:UIControlEventTouchUpInside];   
    cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row]; 

    return cell; 
} 
+0

你有什么问题部分误差与?调试器将显示问题的确切位置。 –

+0

由于索引1超出范围[0..0] – seggy

+0

在哪里填充FavTablename和FavIdent数组,因为此数组可能少于您的numberofrows数。 –

NSString *strfavarry = [NSString stringWithFormat:@"SELECT Title FROM %@ WHERE identifire='%@'",[FavTablename objectAtIndex:indexPath.row],[FavIdent objectAtIndex:indexPath.row]]; 

此行给出了错误,因为你的numberofrows计数大于这些阵列计数值更大。

请检查您的numberofrows count并FavTablenameFavIdent阵列数是否相同。

+0

所有元素是我将检查这两个数组相同@Pooja Srivastava – seggy

这个错误意味着你试试从索引1中的数组中获取一个元素,并且您将超出界限。

大概问题是:

[FavTablename objectAtIndex:indexPath.row] 

检查,如果你的阵列有从中读取之前的一些元素。

要确认你的问题使异常断点:

enter image description here

+0

在表名有12件 – seggy

+0

@seggy启用异常断点所以 –

+0

香港乐施会,我会尝试使用添加异常断点 – seggy

正如你所说,FavTitleFavtablename具有相同数量的元素。因此,尝试把一个异常处理cellForRowAtIndexPath如下: -

if(FavTitle.count > indexPath.row){ 
     cell.lbltitle.text=[FavTitle objectAtIndex:indexPath.row]; 
    }