次のメソッドを呼び出した後、この例外が発生します。アプリが初めて読み込まれたときにのみ表示されます。私は再びアプリを開くときにうまく動作します。誰も助けることができますか?Exc_Bad_Access Iphoneでデータベースを作成する際の例外
-(void) createAndCheckDatabase
{
BOOL success;
self.databaseName = @"database.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
self.databasePath = [[documentDir stringByAppendingPathComponent:self.databaseName]retain];
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:self.databasePath];
if(success) return;
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseName];
NSError *err;
[fileManager copyItemAtPath:databasePathFromApp toPath:self.databasePath error:nil];
if (err) {
// DebugLog(@"%@", [err description]);
}
}
あなたは私たちにプロパティを貼り付けることができますか:self.databaseName?それは何ですか?保持しますか? –
@ JonasSchnelliはいその保持 –
これはメモリリークを作るようです: 'self.databasePath = [[documentDir stringByAppendingPathComponent:self.databaseName] retain];' 'retain'を削除します。しかし、クラッシュはそこから来るべきではありません。デバッガを使ってメソッドを実行しましたか?それはどこでクラッシュするのですか? –