Я получаю эту ошибку при попытке представить сохраненные даты
мой вопрос, что это за ошибка?
ошибка:
2011-11-13 10:06:36.001 Holiday[217:207] -[NSNull cc_componentsForMonthDayAndYear]: unrecognized selector sent to instance 0x259ed68
2011-11-13 10:06:36.039 Holiday[217:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull cc_componentsForMonthDayAndYear]: unrecognized selector sent to instance 0x259ed68'
*** Call stack at first throw:
(
0 CoreFoundation 0x02534b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0268440e objc_exception_throw + 47
2 CoreFoundation 0x025366ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x024a62b6 ___forwarding___ + 966
4 CoreFoundation 0x024a5e72 _CF_forwarding_prep_0 + 50
5 Holiday 0x00008c7e +[KalDate dateFromNSDate:] + 44
6 Holiday 0x0000fc36 -[KalViewController loadedDataSource:] + 265
7 Holiday 0x000081d4 -[HolidaySqliteDataSource loadHolidaysFrom:to:delegate:] + 873
8 Holiday 0x00008560 -[HolidaySqliteDataSource presentingDatesFrom:to:delegate:] + 97
9 Holiday 0x0000f848 -[KalViewController reloadData] + 162
10 Holiday 0x0000fe16 -[KalViewController showAndSelectDate:] + 276
11 Holiday 0x000065ab -[HolidayAppDelegate showAndSelectToday] + 90
12 UIKit 0x002e27f8 -[UIApplication sendAction:to:from:forEvent:] + 119
13 UIKit 0x004ee68b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
14 UIKit 0x002e27f8 -[UIApplication sendAction:to:from:forEvent:] + 119
15 UIKit 0x0036dde0 -[UIControl sendAction:to:forEvent:] + 67
16 UIKit 0x00370262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
17 UIKit 0x0036ee0f -[UIControl touchesEnded:withEvent:] + 458
18 UIKit 0x003063d0 -[UIWindow _sendTouchesForEvent:] + 567
19 UIKit 0x002e7cb4 -[UIApplication sendEvent:] + 447
20 UIKit 0x002ec9bf _UIApplicationHandleEvent + 7672
21 GraphicsServices 0x02d90822 PurpleEventCallback + 1550
22 CoreFoundation 0x02515ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
23 CoreFoundation 0x02476807 __CFRunLoopDoSource1 + 215
24 CoreFoundation 0x02473a93 __CFRunLoopRun + 979
25 CoreFoundation 0x02473350 CFRunLoopRunSpecific + 208
26 CoreFoundation 0x02473271 CFRunLoopRunInMode + 97
27 GraphicsServices 0x02d8f00c GSEventRunModal + 217
28 GraphicsServices 0x02d8f0d1 GSEventRun + 115
29 UIKit 0x002f0af2 UIApplicationMain + 1160
30 Holiday 0x00001fd4 main + 102
31 Holiday 0x00001f65 start + 53
32 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
представление кода функции:
- (void)loadHolidaysFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id<KalDataSourceCallbacks>)delegate
{
NSLog(@"Fetching holidays from the database between %@ and %@...", fromDate, toDate);
sqlite3 *db;
NSDateFormatter *fmt = [[[NSDateFormatter alloc] init] autorelease];
if(sqlite3_open([[self databasePath] UTF8String], &db) == SQLITE_OK) {
const char *sql = "select name, country, date_of_event from holidays where date_of_event between ? and ?";
sqlite3_stmt *stmt;
if(sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
[fmt setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
sqlite3_bind_text(stmt, 1, [[fmt stringFromDate:fromDate] UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, [[fmt stringFromDate:toDate] UTF8String], -1, SQLITE_STATIC);
[fmt setDateFormat:@"yyyy-MM-dd"];
while(sqlite3_step(stmt) == SQLITE_ROW) {
NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
NSString *country = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
NSString *dateAsText = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 2)];
[holidays addObject:[Holiday holidayNamed:name country:country date:[fmt dateFromString:dateAsText]]];
}
}
sqlite3_finalize(stmt);
}
sqlite3_close(db);
[delegate loadedDataSource:self];
}
функция вставки, которая вставляет даты
-(NSNumber*) insertDate: (NSDate*) d
{
NSLog(@"inserting date into database");
sqlite3 *db;
NSNumber *re = [NSNumber numberWithInt:-1];
NSDateFormatter *fmt = [[[NSDateFormatter alloc]init]autorelease];
if(sqlite3_open([[self databasePath]UTF8String],&db)==SQLITE_OK){
const char *sql = "insert into holidays(name, country, date_of_event) values(?,?,?)";
sqlite3_stmt *addStmt;
if(sqlite3_prepare_v2(db,sql,-1,&addStmt,NULL)==SQLITE_OK){
[fmt setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSString *country = @"country test";
NSString *name =@"name test";
sqlite3_bind_text(addStmt,1,[name UTF8String],-1,SQLITE_STATIC);
sqlite3_bind_text(addStmt,2,[country UTF8String],-1,SQLITE_STATIC);
sqlite3_bind_text(addStmt,3,[[fmt stringFromDate:d]UTF8String],-1,SQLITE_STATIC);
}
if(SQLITE_DONE != sqlite3_step(addStmt)){
NSAssert1(0,@"Error in inserting into database %s",sqlite3_errmsg(db));
}else {
re = [NSNumber numberWithInt: sqlite3_last_insert_rowid(db)];
sqlite3_finalize(addStmt);
sqlite3_close(db);
}
}
return re;
}