Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 由于未捕获异常而终止应用程序';nsrange异常';给出范围或索引超出范围';_Iphone_Location_Nsrange - Fatal编程技术网

Iphone 由于未捕获异常而终止应用程序';nsrange异常';给出范围或索引超出范围';

Iphone 由于未捕获异常而终止应用程序';nsrange异常';给出范围或索引超出范围';,iphone,location,nsrange,Iphone,Location,Nsrange,我正在开发条形码应用程序,并从CLController获取位置,因此它给出了位置、速度和许多其他内容,因此我将其与范围进行了子串,并获得异常,因此请告诉我原因,以及我应该为此做些什么 提前谢谢 - (void)locationUpdate:(CLLocation *)location { locstr = [location description ]; //NSLog(@"current location is %@ ",locstr); NSString* regexString =@"

我正在开发条形码应用程序,并从CLController获取位置,因此它给出了位置、速度和许多其他内容,因此我将其与范围进行了子串,并获得异常,因此请告诉我原因,以及我应该为此做些什么

提前谢谢

- (void)locationUpdate:(CLLocation *)location {

locstr = [location description ];
//NSLog(@"current location is %@ ",locstr);

NSString* regexString =@"<(.*?)>";
NSRegularExpressionOptions options = NSRegularExpressionCaseInsensitive;
NSError* error = NULL;

NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:regexString options:options error:&error];
if (error) {
    //NSLog(@"error is %@", [error description]);
}

NSArray* results = [regex matchesInString:locstr options:0 range:NSMakeRange(1, [locstr length])];
for (NSTextCheckingResult* result in results) {


    resultString = [locstr substringWithRange:result.range];
    //NSLog(@"%@",resultString);
    //life = [[resultString substringWithRange:NSMakeRange(1)] retain];
    resultString =[resultString substringWithRange:NSMakeRange(1,27)];

    resultString = [resultString stringByReplacingOccurrencesOfString:@" "
                                                           withString:@""];
    life = [resultString stringByReplacingOccurrencesOfString:@"+"
                                                   withString:@""];
    life = [[life substringWithRange:NSMakeRange(0,[life length]-1)] retain];
    //NSLog(@"in update %@",life);


}
-(无效)位置更新:(CLLocation*)位置{
locstr=[位置描述];
//NSLog(@“当前位置为%@”,locstr);
NSString*regexString=@;
NSRegularExpressionOptions=nsregularexpressioncase不敏感;
n错误*错误=NULL;
NSRegularExpression*regex=[NSRegularExpression regular expressionwithpattern:regexString选项:选项错误:&error];
如果(错误){
//NSLog(@“错误为%@”,[错误描述]);
}
NSArray*results=[regex-matchesisnstring:locstr-options:0-range:NSMakeRange(1[locstr-length]);
for(NSTextCheckingResult*结果输入结果){
resultString=[locstr substringWithRange:result.range];
//NSLog(@“%@”,结果字符串);
//寿命=[[resultString substringWithRange:NSMakeRange(1)]保留];
结果字符串=[resultString substringWithRange:NSMakeRange(1,27)];
resultString=[resultString stringByReplacingOccurrencesOfString:@]
带字符串:@“];
life=[resultString stringByReplacingOccurrencesOfString:@“+”
带字符串:@“];
寿命=[[life substringWithRange:NSMakeRange(0,[life length]-1)]保留];
//NSLog(@“更新%@”,寿命);
}
}

获取此异常

2011-11-23 14:24:58.161条形码应用程序[2632:707]*终止应用程序到期 要取消捕获异常“NSRangeException”,原因: -[NSRegularExpression枚举匹配安装:选项:范围:使用块:]:范围或索引 越界的第一次抛出调用堆栈:(0x326398bf 0x364a31e5) 0x326397b9 0x326397db 0x3783846b 0x37838a11 0x37af 0xbe73 0x3548f5df 0x3548ef81 0x3548962f 0x3260db31 0x3260d15f 0x3260c381 0x3258f4dd 0x3258f3a5 0x37cd0fed 0x30eda743 0x2337 0x22b8)终止调用 抛出异常程序收到信号:“SIGABRT”。数据 格式化程序暂时不可用,将在“继续”后重试。 (找不到dlopen函数,因此无法加载共享 图书馆。)

您确定
resultString
长度大于27吗?无论如何,如果它小于27,它将崩溃。似乎应用程序在那里崩溃了。也可能在您使用过NSRange的其他地方

使NSZombie能够准确地获取应用程序崩溃的位置

您确定
resultString
长度大于27吗?无论如何,如果它小于27,它将崩溃。似乎应用程序在那里崩溃了。也可能在您使用过NSRange的其他地方


启用NSZombie以获取应用程序崩溃的确切位置。

为什么要解析
[CLLocation description]
而不是使用位置、精度等属性?描述不应该这样使用。

为什么要解析
[CLLocation description]
而不是使用属性,如位置、精度等?描述不应该这样使用。

dito Aadhira

该应用程序也可能在运行时崩溃

NSMakeRange(1, [locstr length])
在此处定义从1到[locstr长度]的范围,而[locstr长度]必须是[locstr长度]-1

字符串“NSMakeRange”的长度为11个字符。所以,它的数组索引范围是0-10。覆盖您的代码,范围将是1-11,因为您从1开始,在1+10=11停止。

dito Aadhira

该应用程序也可能在运行时崩溃

NSMakeRange(1, [locstr length])
在此处定义从1到[locstr长度]的范围,而[locstr长度]必须是[locstr长度]-1

字符串“NSMakeRange”的长度为11个字符。所以,它的数组索引范围是0-10。覆盖您的代码,范围将是1-11,因为您从1开始,在1+10=11停止