|Feb 3, 2013, 10:53 AM||#1|
I have an encoding syntax error that crashes an app with with NSString
I have an encoding syntax error that crashes an app with a "*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithCString:encoding:]: NULL cString'
here's the code:
// encoding fix cell.titleLabel.text = [[NSString stringWithCString:[[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding]]capitalizedString];
Any idea how to fix this?
Last edited by maflynn; Feb 3, 2013 at 01:30 PM.
|Feb 3, 2013, 11:28 AM||#3|
Break it down.
Does [item objectForKey:@"main_tag"] return nil or a valid object? Exactly what type is the object?
Does cStringUsingEncoding:NSISOLatin1StringEncoding return a valid C string? Exactly what does it show up as (e.g. NSLog it with the proper conversion specifier)?
What does NSString stringWithCString: return? Again, verify what you expect using the debugger or NSLog.
What does capitalizedString return?
We know what you can expect each of those steps to do, but what does each one actually do? Where's your evidence that each step is doing what it should?
If you have to add some intermediate variables to allow seeing each step's values in the debugger, or NSLog'ing them, then add the intermediate variables.
Right now, you've used all your skill to write a complex expression. What skill will you now use to debug this complex expression? Break the complex problem down into a series of solvable sub-problems, then solve each sub-problem in turn. That's how you fix complex problems: by breaking them down.
|Feb 3, 2013, 11:54 AM||#4|
each NSLog(@"cell.titleLabel.text %@",cell.titleLabel.text);
[item objectForKey:@"main_tag"] outputs the name of a title, occasionally it encounters a NULL value. When the cstring encoding is performed on it there's a crash.
the NSLog output is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithCString:encoding:]: NULL cString'
|Feb 3, 2013, 12:47 PM||#5|
Show your actual code, and the actual output produced by the code.
A C string is not an object. Therefore, "%@" in the format string will not work with it.
An "occasional" NULL value is enough to make the entire series of steps fail. Exactly which step is producing the NULL?
I already know which step is crashing, but that's not the one producing the NULL. It's just the one where the NULL is fatal. Some step BEFORE the crash is producing a NULL. Find that step, and find out why it's producing a NULL.
If you're expecting a NULL from that step, then why aren't you handling the possibility of a NULL?
If you're not expecting a NULL, then your expectation is clearly wrong, or something else is not working before the code reaches the step that produces the NULL.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Spinning Wheel crashes at start up, Not an error with actual hard drive.||Uddername||MacBook Pro||4||Jan 9, 2014 06:07 PM|
|MacMini crashes, gives grey error screen. Log inside. Any advice?||redboardprod||Mac Basics and Help||3||Oct 25, 2013 08:58 PM|
|Syntax Error - help please! :(||Brradley||Mac Programming||3||May 7, 2013 05:52 PM|
|WebDAV Apache2 Syntax Error||iBlink||Mac OS X Server, Xserve, and Networking||0||Jan 23, 2013 01:43 AM|
|iPod touch apps always crashes no error||chimmy||iPod touch||1||Jun 5, 2012 03:02 PM|
All times are GMT -5. The time now is 03:55 AM.