简体   繁体   English

由于未捕获的异常“ NSRangeException”而终止应用程序,原因:“ ***-[NSMutableArray objectAtIndex:]:索引26超出范围[0 .. 0]”

[英]Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 26 beyond bounds [0 .. 0]'

I would appreciate some help. 我将不胜感激。 I have used this before and it worked fine. 我以前使用过它,并且效果很好。 I tried to use it in a new app and it breaks. 我试图在新应用中使用它,但它坏了。 I understand it is a problem with the index, but I can't pin point it. 我知道索引存在问题,但我无法指出。

    self.greensArray = [NSMutableArray array];
    for (int i = 0; i < 26; ++i) {
    [self.greensArray addObject:[NSMutableArray array]];
    }


letterIndex =[[NSMutableArray alloc] init];

NSMutableArray *name = [searchViewArray valueForKey:@"meatName"];
for (int i = 0; i < [name count]; ++i) {
    NSUInteger firstLetter = [ALPHA rangeOfString:[[name objectAtIndex:i ] substringToIndex:1]].location;
    [self.greensArray insertObject:[NSMutableArray array] atIndex:i];
    if (firstLetter != NSNotFound) {
        [[self.greensArray objectAtIndex:firstLetter] addObject:[name objectAtIndex:i]];
    }
    char alphabet = [[name objectAtIndex:i] characterAtIndex:0];
    NSString *uniChar = [NSString stringWithFormat:@"%C",alphabet];
    if(![letterIndex containsObject:uniChar])
    {
        [letterIndex addObject:uniChar];

    }
}

The problem was here: [self.greensArray insertObject:[NSMutableArray array] atIndex:i]; 问题出在这里:[self.greensArray insertObject:[NSMutableArray array] atIndex:i]; I don't know why this worked in my first application, but this line of code added additional values to the greensArray. 我不知道为什么这在我的第一个应用程序中有效,但是这一行代码为greensArray添加了附加值。 That threw off the integer / meatName count and made the whole app crash. 那扔掉了整数/ meatName计数,并使整个应用程序崩溃。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ***由于未捕获的异常&#39;NSRangeException&#39;而终止应用程序,原因:&#39;***-[NSMutableArray objectAtIndex:]:索引1超出范围[0 .. 0]&#39; - *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 由于未捕获的异常&#39;NSRangeException&#39;终止应用程序,原因:&#39;*** - [NSMutableArray objectAtIndex:]:索引1超出边界[0 .. 0]&#39; - Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]' ***由于未捕获的异常&#39;NSRangeException&#39;而终止应用程序,原因:&#39;*** - *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** &#39;NSRangeException&#39;,原因:&#39;* -[__NSArrayM objectAtIndex:]:索引 2 超出范围 [0 .. 1]&#39; - 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]' iPhone-ReplaceScene错误:由于未捕获的异常&#39;NSRangeException&#39;,正在终止应用程序,原因:&#39;***-[NSMutableArray replaceObjectAtIndex:withObject:] - iphone - replaceScene error:Terminating app due to uncaught exception 'NSRangeException',reason:'***-[NSMutableArray replaceObjectAtIndex:withObject:] 因未捕获的异常“NSRangeException”而终止应用程序会使Range或index超出范围 - Terminating app due to uncaught exception 'NSRangeException' gives Range or index out of bounds' 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[NSDecimalNumber objectAtIndex:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber objectAtIndex:] 异常“ NSRangeException”,原因:“ ***-[__ NSArray0 objectAtIndex:]:空NSArray的索引0超出范围” - exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray' iOS:致命异常:NSRangeException ***-[__ NSArrayM objectAtIndex:]:索引1超出范围[0 .. 0] - iOS: Fatal Exception: NSRangeException *** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0] Xcode - 由于未捕获的异常&#39;NSRangeException&#39;而终止应用程序 - Xcode - Terminating app due to uncaught exception 'NSRangeException'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM