Uncaught exception on 'Open Failed' while following chapter


#1

Hi all

I am following the code in the Core Data chapter and I can’t seem to run it successfully. I’ve already tried it on both simulator and my iphone and both returns an exception.

I’m getting this exception call:

2013-11-25 10:31:29.349 Homepwner[676:c07] *** Terminating app due to uncaught exception 'Open Failed', reason: 'Reason: The operation couldn’t be completed. (Cocoa error 512.)' *** First throw call stack: (0x15cb012 0x13f0e7e 0x15cadeb 0x4952 0x4668 0x3872 0x519548 0x51c224 0x3e0952 0x3e02dc 0x455b 0x418103 0x41842b 0x42dfad 0x42e89b 0x42e9b9 0x42ea45 0x53420b 0x3852dd 0x14046b0 0x2eeafc0 0x2edf33c 0x2eeaeaf 0x4242bd 0x36cb56 0x36b66f 0x36b589 0x36a7e4 0x36a61e 0x36b3d9 0x36e2d2 0x41899c 0x365574 0x36576f 0x365905 0x36e917 0x23ef 0x332157 0x332747 0x33394b 0x344cb5 0x345beb 0x337698 0x2418df9 0x2418ad0 0x1540bf5 0x1540962 0x1571bb6 0x1570f44 0x1570e1b 0x33317a 0x334ffc 0x20ed 0x2015) libc++abi.dylib: terminate called throwing an exception

Based from that, I know that the problem comes from the init function of BNRItemStore. Here is the code in the init function:

[code]- (id)init
{
self = [super init];
if(self)
{
//allItems = [[NSMutableArray alloc] init];

    //NSString *path = [self itemArchivePath];
    //allItems = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    
    // If the array hadn't been saved previously, create a new empty one
    //if(!allItems)
        //allItems = [[NSMutableArray alloc] init];
    
    // Read in Homepwner.xcdatamodeld
    model = [NSManagedObjectModel mergedModelFromBundles:nil];
    
    NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
    
    // Where does this SQLite file go?
    NSString *path = [self itemArchivePath];
    NSURL *storeURL = [NSURL fileURLWithPath:path];
    
    NSError *error = nil;
    
    if(![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {
        [NSException raise:@"Open Failed" format:@"Reason: %@", [error localizedDescription]];
    }
    
    // Create the managed object context
    context = [[NSManagedObjectContext alloc] init];
    // and set the psc as the persistent store
    [context setPersistentStoreCoordinator:psc];
    
    // The managed object context can manage undo, but we don't need it
    [context setUndoManager:nil];
    
    [self loadAllItems];
}

return self;

}[/code]

Does anyone know why this happens? Please let me know.

Thanks

EDIT: Solved. Found the problem here: http://forums.bignerdranch.com/viewtopic.php?f=241&t=5473