Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 3, 2013, 09:53 AM   #1
hanuman99
macrumors newbie
 
Join Date: Nov 2010
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'
" crash

here's the code:
Code:
// encoding fix
cell.titleLabel.text = [[NSString stringWithCString:[[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding]]capitalizedString];
apparently there's a double conversion occurring and that's why the call to cStringUsingEncoding:NSISOLatin1StringEncoding returns NULL).

Any idea how to fix this?

thanks!

Last edited by maflynn; Feb 3, 2013 at 12:30 PM.
hanuman99 is offline   0 Reply With Quote
Old Feb 3, 2013, 10:20 AM   #2
xStep
macrumors 68000
 
Join Date: Jan 2003
Location: Lost in Minneapolis
Break that combined line into individual lines. It will mle analyzing the problem easier and if there is a conflict may even fix the issue.
xStep is offline   1 Reply With Quote
Old Feb 3, 2013, 10:28 AM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
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.
chown33 is offline   1 Reply With Quote
Old Feb 3, 2013, 10:54 AM   #4
hanuman99
Thread Starter
macrumors newbie
 
Join Date: Nov 2010
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'
hanuman99 is offline   0 Reply With Quote
Old Feb 3, 2013, 11:47 AM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
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.
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
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 05:07 PM
MacMini crashes, gives grey error screen. Log inside. Any advice? redboardprod Mac Basics and Help 3 Oct 25, 2013 07:58 PM
Syntax Error - help please! :( Brradley Mac Programming 3 May 7, 2013 04:52 PM
WebDAV Apache2 Syntax Error iBlink Mac OS X Server, Xserve, and Networking 0 Jan 23, 2013 12:43 AM
iPod touch apps always crashes no error chimmy iPod touch 1 Jun 5, 2012 02:02 PM

Forum Jump

All times are GMT -5. The time now is 03:46 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC