我是新的iPhone應用程序開發者,我使用sqlite3的數據庫和應用程序委託我是賴特下面的代碼並運行正常,我們在我的aplication也找到數據庫的價值,如何解決運行時錯誤NSString,sqlite3_column_text NULL的問題?
,而是立即申請是要粗魯爲什麼這是發生我不明白。
代碼波紋管給
-(void)Data
{
databaseName = @"dataa.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath =[documentsDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
list1 = [[NSMutableArray alloc] init];
sqlite3 *database;
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
if(detailStmt == nil)
{
const char *sql = "Select * from Dataa";
if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) == SQLITE_OK)
{
//NSLog(@"Hiiiiiii");
//sqlite3_bind_text(detailStmt, 1, [t1 UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_text(detailStmt, 2, [t2 UTF8String], -2, SQLITE_TRANSIENT);
//sqlite3_bind_int(detailStmt, 3, t3);
while(sqlite3_step(detailStmt) == SQLITE_ROW)
{
//NSLog(@"Helllloooooo");
NSString *item= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 0)];
//NSString *fame= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 1)];
//NSString *cinemax = [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 2)];
//NSString *big= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 3)];
//pvr1 = pvr;
item1=item;
//NSLog(@"%@",item1);
data = [[NSMutableArray alloc] init];
list *animal=[[list alloc] initWithName:item1];
// Add the animal object to the animals Array
[list1 addObject:animal];
//[list1 addObject:item];
}
sqlite3_reset(detailStmt);
}
sqlite3_finalize(detailStmt);
// sqlite3_clear_bindings(detailStmt);
}
}
detailStmt = nil;
sqlite3_close(database);
}
,當我們看到控制檯它們顯示出以下錯誤給波紋管
2010-03-09 10:02:40.262 SanjeevKapoor[430:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'
當我們看到調試器,他們在下面一行
顯示錯誤 NSString *item= [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 0)];
我無法解決問題plz幫助我。
它不是你的問題的根本原因(後發生),但此行是*非常*奇怪:列表*動物= [[列表頁頭] initWithName:項目1]。這個alloc應該在一個Class名字上執行,在這裏你似乎用一個變量來調用它! – yonel 2010-03-09 08:38:27
list * animal = [[list alloc] initWithName:item1]; 是可以的,因爲「list」是類,而不是變量。 這只是看起來很奇怪,因爲在蘋果的風格類名稱始終以大寫字母開頭。 – Vladimir 2010-03-09 17:14:21