***由于未捕获的异常'NSRangeException'而终止应用程序,原因:'***-[__ NSArrayM objectAtIndex:]:索引5超出范围[0 .. 4]' [英] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'

查看:204
本文介绍了***由于未捕获的异常'NSRangeException'而终止应用程序,原因:'***-[__ NSArrayM objectAtIndex:]:索引5超出范围[0 .. 4]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到 *由于未捕获的异常'NSRangeException'而终止应用程序,原因:'*

我没有得到确切的位置问题,请对此提供帮助

I am not getting where is exact issue please help me on this

- (NSMutableArray*) arrayAtPointIndex:(NSInteger) index {
    NSMutableArray * array = [[NSMutableArray alloc] init];
    if ( series )
    {
        for (int plotIndex = 0; plotIndex <= [_points count]; plotIndex++) {
            SALChartCoordinate * coord1 = [_points objectAtIndex:plotIndex];
            CGFloat differ = abs( [[coord1.series objectAtIndex:index] floatValue] );
            [array addObject:[NSNumber numberWithFloat:differ]];
        }

    }
    if ( [array count] > 0 )
        return [array autorelease];

    [array release];
    return nil;
}


推荐答案

最可能的位置是: [coord1.series objectAtIndex:index]

因为您没有检查NSArray系列的大小和plotIndex。

Because you are not checking that NSArray series size and plotIndex.

设置类似这样的条件

if(coord1.series.count-1 <= index)
{
     CGFloat differ = abs( [[coord1.series objectAtIndex:plotIndex] floatValue] );
     [array addObject:[NSNumber numberWithFloat:differ]];
}

注意:您正在访问数组和内部数组具有相同的索引。不能肯定地说,但这表明存在一些逻辑问题。所以检查一下。

NOTE: You are accessing array and inner array with same index. It can not be said for sure but this is indicating some logic problem. So check for that.

这篇关于***由于未捕获的异常'NSRangeException'而终止应用程序,原因:'***-[__ NSArrayM objectAtIndex:]:索引5超出范围[0 .. 4]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆