App crashing "due to uncaught exception" - objective-c

My app always crashes and goes to the main.m file. It shows the following error in the output:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
libc++abi.dylib: terminating with uncaught exception of type NSException
How do I fix this?

This error implies that there is the function initFileURLWithPath:isDirectory: being called on a NSURL with a parameter being nil. Check your parameters that call this function and make sure they're not nil.
Hope that helps :)

This mean that [NSURL initFileURLWithPath:isDirectory:] nil so it crash.
You should put breakpoint and run again to find where is it crash. You can see image below:

Related

Unrecognized selector sent to instance IOS 10

I have a very difficult problem when I launched my app on IOS10.3.3.. Indeed, I got this error in my splashviewController :
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// [[EMAnalyticsManager sharedInstance]sendScreenViewWithName:SplashScreen];
}
I got this crash message:
[__NSCFString nsli_lowerAttribute:intoExpression:withCoefficient:forConstraint:]: unrecognized selector sent to instance 0x165e3630
2018-09-06 16:57:31.456059+0100 **********[2461:1072580] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString nsli_lowerAttribute:intoExpression:withCoefficient:forConstraint:]: unrecognized selector sent to instance 0x165e3630'
I made many research to understand the cause of this crash that didn't occur in IOS11.
Any help please??
Some constraints might be causing this when the very first view controller is loaded. Please check your constraint and you can also remove the constraints and then verify if it works.

Is there anyway to check if my app calls any method exclusive for iOS 8?

After testing my app in a iOS 7 device, I got a crash calling containsString from NSString, and then I realised that that methods has NS_AVAILABLE(10_10, 8_0);
Is there anyway to check automatically my program to see if there is any other method that is not available in iOS 7?
How is possible to compile and app with deployment target of 7.0 and not saying any warning or error in these cases?
-[__NSCFString containsString:]: unrecognized selector sent to instance 0x1702297c0
2015-10-23 12:03:37.655 WA[1434:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString containsString:]: unrecognized selector sent to instance 0x1702297c0'
* First throw call stack:
(0x183bd2f50 0x1900dc1fc 0x183bd7c04 0x183bd5930 0x183af55dc 0x1002a2c08 0x1000c71dc 0x1000caa88 0x1000c69bc 0x1000f3a4c 0x186c1055c 0x186c0ff08 0x186c099ec 0x186b9d8cc 0x186b9cad0 0x186c09044 0x1897bb504 0x1897bb030 0x183b92e90 0x183b92df0 0x183b91014 0x183ad1c20 0x186c081c8 0x186c02fdc 0x1000b6040 0x1906cfaa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
You should use rangeOfString instead of containsString. Since rangeOfString available from iOS 2.0, you will not get crash on this.
Code snippets,
NSString *string = #"https://www.google.co.in/";
NSString *substring = #"http";
if ([oneContent rangeOfString:subString].location == NSNotFound) {
NSLog(#"string does not contain substring");
} else {
NSLog(#"string contains substring!");
}
Otherwise you can add category class for NSString and have a method like containsString: where you can implement the above code. It'll work dynamically.

Cannot share from iOS to GooglePlus

I'm working on social package in my app and I developed sharing using multiple social networks. While implementing Google+ SDK for iOS, I logged in and retrieved my account information, but when I start sharing, the application crashes
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
[shareBuilder setPrefillText:obj_featured.title];
UIImage *image = [self captureScreenShot];
[shareBuilder attachImage:image];
[shareBuilder open];
Simply, I commented and test every line, the problem is with the -open function.
The error appears for me when running over real device is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(0x2e783fd3 0x38ffcccf 0x2e6c2463 0x2e6c222b 0x1e7cd5 0x1c014f 0x1e9f31 0x1ea21d 0x1ea429 0x1c07f3 0x201179 0x2f16cc73 0x2e74f25b 0x2e74e72b 0x2e74cf1f 0x2e6b7f0f 0x2e6b7cf3 0x33610663 0x3100316d 0x106131 0x39509ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

What situation can cause Terminating app due to uncaught exception of class 'nil'

My app crashed occasionally with
2012-10-10 23:19:24.039 [26442:850f] -[NSNull allKeys]: unrecognized selector sent to instance 0x7fff741cbea0
2012-10-10 23:19:24.040 [26442:850f] *** Terminating app due to uncaught exception of class 'nil'
The object has already been tested [obj isKindOfClass:[NSDictionary class]] before call allKeys:
and if I call [[NSNull null] allKeys] intentionally, it crashes with
2012-10-11 16:22:15.606 [14939:403] -[NSNull allKeys]: unrecognized selector sent to instance 0x7fff73659f00
2012-10-11 16:22:15.622 [14939:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull allKeys]: unrecognized selector sent to instance 0x7fff73659f00'
I want to know what situation causes Terminating app due to uncaught exception of class 'nil' so I can debug this problem.
1: Because NSNull doesn't respond to message [allKeys], so it throws an exception.
2: you should check that your objet can [respondsToSelector:#selector(allKeys)] instead
3: if your NSNull class objet pass the [obj isKindOfClass:[NSDictionary class]], then there is a problem in your control statement

program crashes when trying to present modal view controller

I want to load another xib, and use this simple code:
AddElementViewController *viewToLoad = [[AddElementViewController alloc] initWithNibName:#"AddElementViewController" bundle:nil];
viewToLoad.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:viewToLoad animated:YES];
for some reason it throws me out with this output:
2012-03-11 11:56:57.990 Weesh[14650:11603] -[MainViewController AddPressed:]: unrecognized selector sent to instance 0x7b55b40
2012-03-11 11:56:57.991 Weesh[14650:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController AddPressed:]: unrecognized selector sent to instance 0x7b55b40'
*** First throw call stack:
(0x13da052 0x198ed0a 0x13dbced 0x1340f00 0x1340ce2 0x13dbec9 0x32a5c2 0x32a55a 0x3cfb76 0x3d003f 0x3cf2fe 0x34fa30 0x34fc56 0x336384 0x329aa9 0x22c7fa9 0x13ae1c5 0x1313022 0x131190a 0x1310db4 0x1310ccb 0x22c6879 0x22c693e 0x327a9b 0x1cad 0x1c15)
terminate called throwing an exception(lldb)
do you have any idea what can cause it?
Somewhere in your code (it seems to be in AddElementViewController implementation) you are sending message AddPressed: to object of class MainViewController.
The call stack and crash error says that there are no method AddPressed: in class MainViewController.
Try to find all places where you are calling AddPressed: (first of all check loadView, viewDidLoad, viewWillAppear, viewDidAppear, init of AddElementViewController class) and check the type of receiver.