*** Assertion failure in -[AppDelegate createDatabaseExecutableFile] - objective-c

I have application and in application delegate i have code for copy the db file into document folder but it's not working i don't know why because it was working before, and giving following error, please take a look and hope you can find something. Thanks
// Creates a writable copy of the bundled default database in the application Documents directory.
- (void) createDatabaseExecutableFile {
// First, test for existence.
BOOL _successDB;
BOOL _successConfig;
NSFileManager* _fileManager = [NSFileManager defaultManager];
NSError* _error;
NSArray* _paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* _documentsDirectory = [_paths objectAtIndex:0];
NSString* _writableDBPath = [_documentsDirectory stringByAppendingPathComponent:#"turfnutritiontool_ver.db"];
NSString* _writableConfigPath = [_documentsDirectory stringByAppendingPathComponent:#"Configuration.plist"];
_successDB = [_fileManager fileExistsAtPath:_writableDBPath];
_successConfig = [_fileManager fileExistsAtPath:_writableConfigPath];
if (_successDB && _successConfig) {
return;
}
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"turfnutritiontool_ver.db"];
NSString *defaultConfigPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Configuration.plist"];
_successDB = [_fileManager copyItemAtPath:defaultDBPath toPath:_writableDBPath error:&_error];
_successConfig = [_fileManager copyItemAtPath:defaultConfigPath toPath:_writableConfigPath error:&_error];
if (!_successDB || !_successConfig) {
NSAssert1(0, #"Failed to create writable database file with message '%#'.", [_error localizedDescription]);
}
}
This is the error:
2012-04-02 13:52:01.162 TurfNutritionTool_ver_5.1[2379:b903] *** Assertion failure in -[AppDelegate createDatabaseExecutableFile], /Development/TurfNutritionTool_IOS_5.1/TurfNutritionTool/AppDelegate.m:188
2012-04-02 13:52:01.165 TurfNutritionTool_ver_5.1[2379:b903] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writable database file with message 'The operation couldn’t be completed. File exists'.'
*** Call stack at first throw:
(
0 CoreFoundation 0x0179a5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018ee313 objc_exception_throw + 44
2 CoreFoundation 0x01752ef8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x011fc3bb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 TurfNutritionTool_ver_5.1 0x00003fef -[AppDelegate createDatabaseExecutableFile] + 831
5 TurfNutritionTool_ver_5.1 0x00003486 -[AppDelegate application:didFinishLaunchingWithOptions:] + 86
6 UIKit 0x009f9c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
7 UIKit 0x009fbd88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
8 UIKit 0x00a06617 -[UIApplication handleEvent:withNewEvent:] + 1533
9 UIKit 0x009feabf -[UIApplication sendEvent:] + 71
10 UIKit 0x00a03f2e _UIApplicationHandleEvent + 7576
11 GraphicsServices 0x01e21992 PurpleEventCallback + 1550
12 CoreFoundation 0x0177b944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
13 CoreFoundation 0x016dbcf7 __CFRunLoopDoSource1 + 215
14 CoreFoundation 0x016d8f83 __CFRunLoopRun + 979
15 CoreFoundation 0x016d8840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x016d8761 CFRunLoopRunInMode + 97
17 UIKit 0x009fb7d2 -[UIApplication _run] + 623
18 UIKit 0x00a07c93 UIApplicationMain + 1160
19 TurfNutritionTool_ver_5.1 0x00002ddd main + 125
20 TurfNutritionTool_ver_5.1 0x00002d55 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception(lldb)

It says "file exists". Isn't that enough of a clue?
From the NSFileManager docs:
If a file with the same name already exists at dstPath, this method aborts the copy attempt and returns an appropriate error.
By the way, you should check the error after each copy, not once at the end because if an error occurs on the first copy, and the second copy, you'll lose the error information from the first copy.

Related

Data-core NSException

I don't know where is my problem because the entity "Utente" exist.
Error code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente''
*** First throw call stack:
(
0 CoreFoundation 0x0000000101bf0495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016f099e objc_exception_throw + 43
2 CoreData 0x0000000101e76599 +[NSEntityDescription entityForName:inManagedObjectContext:] + 217
3 CoreData 0x0000000101eb2e7e +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 30
4 VucmpraJson 0x000000010000514b -[LoginViewController login:] + 4843
5 UIKit 0x000000010029ef06 -[UIApplication sendAction:to:from:forEvent:] + 80
6 UIKit 0x000000010029eeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7 UIKit 0x000000010037b880 -[UIControl _sendActionsForEvents:withEvent:] + 203
8 UIKit 0x000000010037adc0 -[UIControl touchesEnded:withEvent:] + 530
9 UIKit 0x00000001002d5d05 -[UIWindow _sendTouchesForEvent:] + 701
10 UIKit 0x00000001002d66e4 -[UIWindow sendEvent:] + 925
11 UIKit 0x00000001002ae29a -[UIApplication sendEvent:] + 211
12 UIKit 0x000000010029baed _UIApplicationHandleEventQueue + 9579
13 CoreFoundation 0x0000000101b7fd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000101b7f5f2 __CFRunLoopDoSources0 + 242
15 CoreFoundation 0x0000000101b9b46f __CFRunLoopRun + 767
16 CoreFoundation 0x0000000101b9ad83 CFRunLoopRunSpecific + 467
17 GraphicsServices 0x00000001040d0f04 GSEventRunModal + 161
18 UIKit 0x000000010029de33 UIApplicationMain + 1010
19 VucmpraJson 0x0000000100021d13 main + 115
20 libdyld.dylib 0x00000001025f15fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Code:
#property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
.
.
.
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject * Utente = [NSEntityDescription insertNewObjectForEntityForName:#"Utente" inManagedObjectContext:context];
[Utente setValue: emailText.text forKey:#"email"];
NSError *error;
//[context save:&error];
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
entities: Utente
attributes: email;password
thx to much guys
nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente'
means that your managed object context is nil. Check self.managedObjectContext assignment.
edit
if (! [self managedObjectContext]) {
NSLog(#"You will receive your exception");
} else {
// Insert new entity into specified context
}

Call to UIWebView crashing my app in iOS

I have a WebView in my storyboard. I created an outlet property to that webview in my view controller file. Then in my code in I'm calling it like this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"news1" ofType:#"html" inDirectory:#"/HTML"]];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
The problem is my app is crashing when I run this and I don't really know why. I get this error, but I need help deciphering what the issue is.
2014-05-20 20:18:10.214 MyApp[1789:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(
0 CoreFoundation 0x01f7b1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019fe8e5 objc_exception_throw + 44
2 CoreFoundation 0x01f7afbb +[NSException raise:format:] + 139
3 Foundation 0x0161a92b -[NSURL(NSURL) initFileURLWithPath:] + 123
4 Foundation 0x0161a7fd +[NSURL(NSURL) fileURLWithPath:] + 67
5 MyApp 0x00011c3d -[LVGTutorialVC viewDidLoad] + 205
6 UIKit 0x007dd33d -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x00803345 -[UINavigationController _layoutViewController:] + 39
8 UIKit 0x0080385b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
9 UIKit 0x00803953 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
10 UIKit 0x008048cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x008054e9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x009460d1 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x0072d964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x01a1082b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x01de245a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x01dd6244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x01dd60b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x01d3c7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x01d3db85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x01d3e258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x01f4336e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x01f432bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x01f21254 __CFRunLoopRun + 1076
24 CoreFoundation 0x01f209d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x01f207eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x03eab5ee GSEventRunModal + 192
27 GraphicsServices 0x03eab42b GSEventRun + 104
28 UIKit 0x006bef9b UIApplicationMain + 1225
29 MyApp 0x0002158d main + 141
30 libdyld.dylib 0x0262c701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The HTML file isn't in your bundle or isn't at the path specified. Check the case of the file and folder name. If you build/run in the simulator, you can look through the bundle inside of ~/Library/Application Support/iPhone Simulator/7.1/Applications.
Don't use loadRequest if you want to load html locally. use this
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];

showing elements of dictionary

I have a plist file that contains array of dictionaries, and I'm trying to show in console the elements of the dictionnaries... here is my code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"validrep" ofType:#"plist"];
descArray = [[NSMutableArray alloc] init];
NSString *key = [NSString stringWithFormat:#"test %i",i+1];
NSMutableArray *tabreponses = [[NSMutableArray arrayWithContentsOfFile:path] retain];
NSDictionary *dictreponses = [NSDictionary dictionaryWithObject:[tabreponses objectAtIndex:i] forKey:key];
[descArray addObject:dictreponses];
NSDictionary *dictionary = [descArray objectAtIndex:i];
NSArray *array = [dictionary objectForKey:key];
NSLog(#"the array is %#, it contains %i elements.",array,[array count]);
Till now everythig is working correctly and this is what the console is showing:
2011-12-14 14:52:33.845 Daltonien[1459:b603] the array is {
rep1 = "1 \U00e9toile derri\U00e8re un quadrillage ";
rep2 = "1 lettre B derri\U00e8re un quadrillage";
rep3 = "1 quadrillage seul ";
}, it contains 3 elements.
but it doesn't work when i try to show the first element of the array, i do it like this:
NSLog(#"the array is %#, it contains %i elements, the first element is %# .",array,[array count],[array objectAtIndex:i]);
This results in an exception:
Daltonien[1478:b603] -[__NSCFDictionary objectAtIndex:]:
unrecognized selector sent to instance 0x4b8cbd0
Daltonien[1478:b603] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFDictionary objectAtIndex:]:
unrecognized selector sent to instance 0x4b8cbd0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dca5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1e313 objc_exception_throw + 44
2 CoreFoundation 0x00dcc0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d3b966 ___forwarding___ + 966
4 CoreFoundation 0x00d3b522 _CF_forwarding_prep_0 + 50
5 Daltonien 0x00002cff -[DetailViewController tableView:numberOfRowsInSection:] + 193
6 UIKit 0x004772b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
7 UIKit 0x00474d88 -[UITableViewRowData numberOfRows] + 108
8 UIKit 0x00328677 -[UITableView noteNumberOfRowsChanged] + 132
9 UIKit 0x00335708 -[UITableView reloadData] + 773
10 UIKit 0x00332844 -[UITableView layoutSubviews] + 42
11 QuartzCore 0x01d6aa5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d6cddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d120b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d13294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d1346d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00dab89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d406e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d091d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d08840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d08761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017211c4 GSEventRunModal + 217
22 GraphicsServices 0x01721289 GSEventRun + 115
23 UIKit 0x002c8c93 UIApplicationMain + 1160
24 Daltonien 0x000020c8 main + 102
25 Daltonien 0x00002059 start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception
with what should i change objectAtIndex:i
THANX for helping me.
The problem is this:
Your key, #"test1", is actually a dictionary, not an array...
To get the first key / value of the dictionary, you would do the following
[[myDictionary keys] objectAtIndex:0]
[[myDictionary values] objectAtIndex:0]
If you want the first object in your array, you'll want something like this:
[array objectAtIndex:0];
To loop through all of the objects, this will do it:
for (id someObject in array) {
// Do stuff
}

NSURLRequest throwing runtime error

Trying to create a request only to have a runtime error thrown. Method initiating the request:
- (void)loadMemberData {
//build URL
NSMutableString *url = [[NSMutableString alloc] initWithString:appDelegate.apiURL];
[url appendFormat:#"&subaction=singlestat&memberID=%d", [[NSUserDefaults standardUserDefaults] integerForKey:#"memberID"]];
NSURL *tempURL = [[NSURL alloc] initWithString:url];
NSLog(#"URL: %#", tempURL);
//Create conn
NSURLRequest *request = [[NSURLRequest alloc] requestWithURL:tempURL];
NSLog(#"%#", request);
//conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//[request release];
}
The URL logs correctly. I have even checked the object type to make sure everything is correct, and all seems good. No compile time errors or warnings. Stack Trace & Log:
[Session started at 2011-03-09 15:02:32 -0500.]
2011-03-09 15:02:33.807 NTR Beer Club[17702:207] URL: https://mydomain.com/path/to/file.php?action=get_app_data&subaction=singlestat&memberID=117
2011-03-09 15:02:33.809 NTR Beer Club[17702:207] -[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0
2011-03-09 15:02:33.811 NTR Beer Club[17702:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f0c5c2 objc_exception_throw + 47
2 CoreFoundation 0x00db96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d29366 ___forwarding___ + 966
4 CoreFoundation 0x00d28f22 _CF_forwarding_prep_0 + 50
5 NTR Beer Club 0x00002190 -[MyStats loadMemberData] + 358
6 NTR Beer Club 0x000022c8 -[MyStats viewDidLoad] + 215
7 UIKit 0x004b64f0 -[UINib instantiateWithOwner:options:] + 1556
8 UIKit 0x004b8081 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x002c2943 -[UIApplication _loadMainNibFile] + 172
10 UIKit 0x002c34ca -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
11 UIKit 0x002cddb2 -[UIApplication handleEvent:withNewEvent:] + 1533
12 UIKit 0x002c6202 -[UIApplication sendEvent:] + 71
13 UIKit 0x002cb732 _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x016eda36 PurpleEventCallback + 1550
15 CoreFoundation 0x00d99064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00cf96f7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00cf6983 __CFRunLoopRun + 979
18 CoreFoundation 0x00cf6240 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00cf6161 CFRunLoopRunInMode + 97
20 UIKit 0x002c2fa8 -[UIApplication _run] + 636
21 UIKit 0x002cf42e UIApplicationMain + 1160
22 NTR Beer Club 0x00001b98 main + 102
23 NTR Beer Club 0x00001b29 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
You should be doing
NSURLRequest *request = [NSURLRequest requestWithURL:tempURL];
The requestWithURL: creates NSURLRequest objects that are autorelease-d.
The actual error message says "unrecognized selector" because requestWithURL: is a class method, but you are using it like an instance method.

JSON error on iPhone app

i am getting error when i try to run an app on my simulator.
I have copied the JSON(JSON Framework) project in my app but my simulator crashes when it compiles the below lines,(I am using iOS 4.2)
- (void)viewDidLoad {
[super viewDidLoad];
NSString *jsonString = [NSString stringWithString:#"{\"foo\": \"bar\"}"];
NSDictionary *dictionary = [jsonString JSONValue];
NSLog(#"Dictionary value for \"foo\" is \"%#\"", [dictionary objectForKey:#"foo"]);
}
ERROR:
2011-03-02 13:33:37.304 test[10918:207] -[NSCFString JSONValue]: unrecognized selector sent to instance 0x3034
2011-03-02 13:33:37.308 test[10918:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString JSONValue]: unrecognized selector sent to instance 0x3034'
*** Call stack at first throw:
(
0 CoreFoundation 0x00da7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00efc5c2 objc_exception_throw + 47
2 CoreFoundation 0x00da96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d19366 ___forwarding___ + 966
4 CoreFoundation 0x00d18f22 _CF_forwarding_prep_0 + 50
5 test 0x000025d7 -[testViewController viewDidLoad] + 119
6 UIKit 0x0035e65e -[UIViewController view] + 179
7 test 0x0000237e -[testAppDelegate application:didFinishLaunchingWithOptions:] + 79
8 UIKit 0x002b11fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
9 UIKit 0x002b355e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
10 UIKit 0x002bddb2 -[UIApplication handleEvent:withNewEvent:] + 1533
11 UIKit 0x002b6202 -[UIApplication sendEvent:] + 71
12 UIKit 0x002bb732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x016dda36 PurpleEventCallback + 1550
14 CoreFoundation 0x00d89064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15 CoreFoundation 0x00ce96f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00ce6983 __CFRunLoopRun + 979
17 CoreFoundation 0x00ce6240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00ce6161 CFRunLoopRunInMode + 97
19 UIKit 0x002b2fa8 -[UIApplication _run] + 636
20 UIKit 0x002bf42e UIApplicationMain + 1160
21 test 0x0000230c main + 102
22 test 0x0000229d start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
(gdb)
Try adding -ObjC -all_load to the OTHER_LINKER_FLAGS setting. If that is not an option, you could try to use the SBJsonParser or SBJsonWriter objects directly rather than the category methods.
Make sure that SBJSON files are being compiled!
Target->Build phases->Compile files <- check if the *.m files of SBJSON are there!
Adding -ObjC -all_load to app target->build settings ->Linking ->Other Linker Flags -> Debug worked in XCode 4.
Earlier it was crashing