2011-04-06 47 views
0

我有以下的函数的调用如何处理BAD_EXEC在代码

[[LocationDictionary sharedLocationDictionary] getLocation:[NSDate date]] 

我把这个代码片段在我的应用程序委托和其他地方一样,它工作得很好。但是当我把它里面的的

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 

块它直接分解,出现以下错误:

-[NSCFString objectForIntervalOf:]: unrecognized selector sent to instance 0x5e0b910 
2011-04-06 16:42:56.668 SmarTrek[57331:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForIntervalOf:]: unrecognized selector sent to instance 0x5e0b910' 
*** Call stack at first throw: 

即使当我做:

[[LocationDictionary sharedLocationDictionary] getLocation:[NSDate date]]; 

和变化:

- (id) getLocation:(NSDate *) date 
{ 
    return [locationDic objectForIntervalOf:date]; 
} 

- (id)objectForIntervalOf:(id)object { 
    return nil; 
} 

使用NSZombie我:

*** -[IntervalDictionary objectForIntervalOf:]: message sent to deallocated instance 0x5e23930 
Current language: auto; currently objective-c 
2011-04-06 19:51:43.595 Project[62298:207] *** NSInvocation: warning: object 0x5e23930 of class '_NSZombie_IntervalDictionary' does not implement methodSignatureForSelector: -- trouble ahead 
2011-04-06 19:51:43.595 Project[62298:207] *** NSInvocation: warning: object 0x5e23930 of class '_NSZombie_IntervalDictionary' does not implement doesNotRecognizeSelector: -- abort 

我该如何解决这个问题?

回答

0

看起来你有一些内存问题(很可能是一个对象太早被释放)。 NSZombieEnabled和Clang分析器可能会有所帮助。

+0

查看我的更新 – aherlambang 2011-04-06 23:57:32

+0

您正在做出一个大的假设,这是导致问题的唯一方法调用。至少,使用调试器,打破异常并找出它的中断点。但严重的是,NSZombieEnabled正是为这种事情而设计的。 – 2011-04-07 00:00:03

+0

你是对的,一个对象被释放得太早,但是哪一个呢? – aherlambang 2011-04-07 02:56:22

0

它看起来像你正在发送objectForIntervalOf消息到NSString。由于NSString不响应该消息,你会得到一个异常。

我们需要看看使用objectForIntervalOf的代码。

+0

但它为什么它在应用程序委托上工作,而不是在locationManager委托 – aherlambang 2011-04-06 23:53:53

+0

我不知道。我所知道的是,你正在发送objectForIntervalOf消息到一个NSString,并导致一个异常。 – 2011-04-07 00:10:23