我在向表中插入值数组时发出了问题。我要将联系人详细信息数组插入到表中。也就是说,我在变量中列出了名字,列表变量中的姓氏等。同样我要插入24列..
它抛出一个例外说:
***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [contactlist filepath]:无法识别的选择器发送到实例0xa2af5b0'***第一次抛出调用堆栈:(0x257e012 0x1e06e7e 0x26094bd 0x256dbbc 0x256d94e 0x4b613 0x4b551 0x190c589 0x190a652 0x190b89a 0x190a60d 0x190a785 0x1857a68 0x4a0911 0x49fbb3 0x4ddcda 0x25208fd 0x4de35c 0x4de2d5 0x3c8250 0x2501f3f 0x250196f 0x2524734 0x2523f44 0x2523e1b 0x2ad57e3 0x2ad5668 0xd4affc 0x254d 0x2475)libc ++ abi.dylib:terminate调用抛出异常
任何人都可以帮我解决这个问题吗?
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSLog(@"json.... %@",json);
id jsonObject = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
NSLog(@"jsonObject=%@", jsonObject);
NSArray *checkArray=[jsonObject valueForKey:@"ND"];
cheDisk=[checkArray valueForKey:@"FN"];
cheDisk1=[checkArray valueForKey:@"LN"];
NSLog(@"FN =%@",cheDisk);
NSLog(@"LN =%@",cheDisk1);
fname = [NSString stringWithFormat:@"%@",[cheDisk objectAtIndex:0]];
lname = [NSString stringWithFormat:@"%@",[cheDisk1 objectAtIndex:0]];
[self insertData];
[ContactTableview reloadData];
}
-(void)insertData
{
if (sqlite3_open([[self filepath]UTF8String], &db) == SQLITE_OK)
{
NSString *insertStatement = [NSString stringWithFormat:@"INSERT INTO pu_Contacts (FirstName, LastName) VALUES ('%@', '%@')", fname, lname];
char *error;
sqlite3_exec(db, [insertStatement UTF8String], NULL, NULL, &error)!= SQLITE_OK;
sqlite3_close(db);
}
}
+(NSString *) filepath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"UWdatabase1.sql"];
}
答案 0 :(得分:0)
问题在于此代码:
[self filepath]
您将方法定义为class method
,因此无法使用self
调用该方法。
+(NSString *) filepath
解决方案1:
使用班级名称更改[contactlist filepath];
之类的通话。
解决方案2:
将方法更改为实例方法,如:
- (NSString *) filepath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"UWdatabase1.sql"];
}
答案 1 :(得分:0)
班级名称是什么?按类名更改self
以调用类方法:
if (sqlite3_open([[MyClassName filepath]UTF8String], &db) == SQLITE_OK)