Appliction crashes when i'm trying to select data from database and their is no record
Error:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'".
Query: arrList = [app.sk lookupAllForSQL:@"select * from tblFriendDetail"];
Code for lookupAllForSQL:
- (NSArray *)lookupAllForSQL:(NSString *)sql {
sqlite3_stmt *statement;
id result;
NSMutableArray *thisArray = [NSMutableArray arrayWithCapacity:4];
if ((statement = [self prepare:sql])) {
while (sqlite3_step(statement) == SQLITE_ROW) {
NSMutableDictionary *thisDict = [NSMutableDictionary dictionaryWithCapacity:4];
for (int i = 0 ; i < sqlite3_column_count(statement) ; i++) {
if (sqlite3_column_decltype(statement,i) != NULL &&
strcasecmp(sqlite3_column_decltype(statement,i),"Boolean") == 0) {
result = [NSNumber numberWithBool:(BOOL)sqlite3_column_int(statement,i)];
} else if (sqlite3_column_type(statement, i) == SQLITE_TEXT) {
result = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,i)];
} else if (sqlite3_column_type(statement,i) == SQLITE_INTEGER) {
result = [NSNumber numberWithInt:(int)sqlite3_column_int(statement,i)];
} else if (sqlite3_column_type(statement,i) == SQLITE_FLOAT) {
result = [NSNumber numberWithFloat:(float)sqlite3_column_double(statement,i)];
} else {
result = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,i)];
}
if (result) {
[thisDict setObject:result
forKey:[NSString stringWithUTF8String:sqlite3_column_name(statement,i)]];
}
}
[thisArray addObject:[NSDictionary dictionaryWithDictionary:thisDict]];
}
}
sqlite3_finalize(statement);
return thisArray;
}
Crash Log
#0 0x9599d176 in __kill ()
#1 0x9599d168 in kill$UNIX2003 ()
#2 0x95a2f89d in raise ()
#3 0x95a459bc in abort ()
#4 0x93311fda in __gnu_cxx::__verbose_terminate_handler ()
#5 0x011a823b in _objc_terminate ()
#6 0x9331017a in __cxxabiv1::__terminate ()
#7 0x933101ba in std::terminate ()
#8 0x933102b8 in __cxa_throw ()
#9 0x011a8416 in objc_exception_throw ()
#10 0x0100cef8 in +[NSException raise:format:arguments:] ()
#11 0x0100ce6a in +[NSException raise:format:] ()
#12 0x00a06e35 in +[NSString stringWithUTF8String:] ()
#13 0x0000b6ab in -[SKDatabase lookupAllForSQL:] (self=0x59393e0, _cmd=0xf9ac, sql=0x13564) at SKDatabase.m:97
#14 0x000052f9 in -[addGroupMembers viewWillAppear:] (self=0x4f2ce40, _cmd=0xe194, animated=1 '\001') at addGroupMembers.m:34
#15 0x003649be in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#16 0x0035f32a in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#17 0x00366562 in -[UINavigationController pushViewController:transition:forceImmediate:] ()
#18 0x0035f1c4 in -[UINavigationController pushViewController:animated:] ()
#19 0x00002d68 in -[GroupSelection editFriendListClicked:] (self=0x4f34da0, _cmd=0xdf58, sender=0x4f3a400) at GroupSelection.m:80
#20 0x002a64fd in -[UIApplication sendAction:to:from:forEvent:] ()
#21 0x00336799 in -[UIControl sendAction:to:forEvent:] ()
#22 0x00338c2b in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#23 0x003377d8 in -[UIControl touchesEnded:withEvent:] ()
#24 0x002caded in -[UIWindow _sendTouchesForEvent:] ()
#25 0x002abc37 in -[UIApplication sendEvent:] ()
#26 0x002b0f2e in _UIApplicationHandleEvent ()
#27 0x012ff992 in PurpleEventCallback ()
#28 0x01035944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#29 0x00f95cf7 in __CFRunLoopDoSource1 ()
#30 0x00f92f83 in __CFRunLoopRun ()
#31 0x00f92840 in CFRunLoopRunSpecific ()
#32 0x00f92761 in CFRunLoopRunInMode ()
#33 0x012fe1c4 in GSEventRunModal ()
#34 0x012fe289 in GSEventRun ()
#35 0x002b4c93 in UIApplicationMain ()
#36 0x00002199 in main (argc=1, argv=0xbffff084) at main.m:14
I got the solution. It was because it was getting null value from sqlite table. So, now when i'm entering data i'm taking care that i enter data for all fields although the fields in which i don't have entry i'm entering blank string in it.
User contributions licensed under CC BY-SA 3.0