Persistent Store Does Not Read Data..Exception!


#1

hey
i ve been trying to understand this…but m not able to clear the bug…
the exception is thrown from the code where a new persistent store of SQLite type is added…and the exception says THE OPERATION COULDN’T BE COMPLETED

here’s full code of the exception generated…

Homepwner[29846:b603] *** Terminating app due to uncaught exception 'Open Failed', reason: 'Reason = The operation couldn’t be completed. (Cocoa error 134100.)' *** Call stack at first throw: ( 0 CoreFoundation 0x00fa45a9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x010f8313 objc_exception_throw + 44 2 CoreFoundation 0x00f5cef8 +[NSException raise:format:arguments:] + 136 3 CoreFoundation 0x00f5ce6a +[NSException raise:format:] + 58 4 Homepwner 0x00003cbd -[PossessionStore init] + 541 5 Homepwner 0x00004926 +[PossessionStore defaultStore] + 118 6 Homepwner 0x00003757 -[ItemsViewController tableView:numberOfRowsInSection:] + 71 7 UIKit 0x003b32b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834 8 UIKit 0x003b0d88 -[UITableViewRowData numberOfRows] + 108 9 UIKit 0x00264677 -[UITableView noteNumberOfRowsChanged] + 132 10 UIKit 0x00271708 -[UITableView reloadData] + 773 11 Homepwner 0x0000327d -[ItemsViewController viewDidLoad] + 173 12 UIKit 0x002a6089 -[UIViewController view] + 179 13 UIKit 0x002a47f5 -[UIViewController nextResponder] + 34 14 UIKit 0x002c54a6 -[UIResponder _containsResponder:] + 41 15 UIKit 0x002afc4e -[UINavigationController defaultFirstResponder] + 80 16 UIKit 0x002c4647 -[UIResponder(Internal) _deepestDefaultFirstResponder] + 42 17 UIKit 0x002c4663 -[UIResponder(Internal) _deepestDefaultFirstResponder] + 70 18 UIKit 0x002c4406 -[UIResponder(Internal) _promoteDeepestDefaultFirstResponder] + 42 19 Homepwner 0x00002ae2 -[HomepwnerAppDelegate application:didFinishLaunchingWithOptions:] + 322 20 UIKit 0x001f6c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 21 UIKit 0x001f8d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 22 UIKit 0x00203617 -[UIApplication handleEvent:withNewEvent:] + 1533 23 UIKit 0x001fbabf -[UIApplication sendEvent:] + 71 24 UIKit 0x00200f2e _UIApplicationHandleEvent + 7576 25 GraphicsServices 0x018fc992 PurpleEventCallback + 1550 26 CoreFoundation 0x00f85944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 27 CoreFoundation 0x00ee5cf7 __CFRunLoopDoSource1 + 215 28 CoreFoundation 0x00ee2f83 __CFRunLoopRun + 979 29 CoreFoundation 0x00ee2840 CFRunLoopRunSpecific + 208 30 CoreFoundation 0x00ee2761 CFRunLoopRunInMode + 97 31 UIKit 0x001f87d2 -[UIApplication _run] + 623 32 UIKit 0x00204c93 UIApplicationMain + 1160 33 Homepwner 0x00002969 main + 121 34 Homepwner 0x000028e5 start + 53 ) terminate called throwing an exceptionCurrent language: auto; currently objective-c

Can anyone temme wats going wrong???
the app no longer seems to work…

[PS: Also if i remove the [NSException raiseException…] Code, the app runs but without a persistent store. When the data is trying to save itself, it gets an exception saying:

HELP!


#2

Post the entire init method for BNRPossessionStore?


#3

here’s the init method:

@implementation PossessionStore

- (id)init
{
    // If we already have an instance of PossessionStore...
    if (defaultStore) {
        
        // Return the old one
        return defaultStore;
    }
    
    self = [super init];
    // Read in Homepwner.xcdatamodeld
    model = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
    
    NSPersistentStoreCoordinator *psc = 
    [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
       
    NSString *path = pathInDocumentDirectory(@"store.data");
    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];
    [context setPersistentStoreCoordinator:psc];
    [psc release];
    
    // The managed object context can manage undo, but we don't need it
    [context setUndoManager:nil];
    return self;
}

#4

Hm.

Did you build and run the application and then change the Core Data model file? Try deleting the application from the simulator/device, then performing a Clean (from the Product menu), and trying again.


#5

Thanks a lot…it worked…

but there’s one small issue…the valueInDollars that is getting saved is way too vague…kind of random in nature…i mean if i type in value as 0…it gets 83705680
but in the textfield it shows 0…the table cell shows 83705680…also i tried to print its value to console when it gets saved…it gets 83705680…


#6

I had the same behavoir. Check the format change in ItemDetailViewController.m viewWillAppear: method. stringWithFormat:@"%@" has changed. (Page 306)


#7

I have had similar issues when I change something in the core data. How do you set up your core data so you can change attributes without ruining the app.


#8

Check out NSMigrationManager.


#9

Joe - your recommendation to shutdown the app, remove it from the iPhone and then do a clean build fixed my similar issue. For some reason my data was not getting saved. When I debugged the saveChanges method I found that the error returned was cocoa error 134030. I must have changed the model afterwards. But I got it fixed with your help! :smiley:

Silly question on this topic - is the saveChanges only called when the app is moved to the background? Would it be advisable to call this method from other actions such as when the done button is pressed when adding a new item?