Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jamdr

macrumors 6502a
Original poster
Jul 20, 2003
659
0
Bay Area
I'm new to Obj-C and when I tried to run my application I got this error in the run log:

2006-04-30 01:01:18.940 MyProject[404] NSScanner: nil string argument

I don't really understand what that means because I don't know where in my code the error occurred. Is one of those numbers a line number? XCode's debugger seems really unintuitive. I'm used to eclipse, where if an error occurs you can jump right to the part of your code where the problem is. How can I do this in XCode?
 

szymczyk

macrumors regular
Mar 5, 2006
187
17
You're not running your code in the debugger so Xcode can't tell you the line of code where the error occurred. Choose Debug > Debug Executable to run your program in the debugger, which will make debugging your program much easier.

Regarding the error message, your program is trying to use a nil string pointer. When you declare pointer variables in your program, you must allocate memory for them before you use them.
 

jamdr

macrumors 6502a
Original poster
Jul 20, 2003
659
0
Bay Area
Thanks for the reply. I see the debug mode, but I still don't get it. If I run my code in the debugger and an error occurs, I just see a window pop up full of assembly code. So the error occurred at 0xfffeff20 <+0032> lwz r11,0(r2). Is there a way to get a little more high level than that? Also is there a way to see what the current values of local variables are? I see a memory window, but again it's just registers and hex values. Is there no higher-level debug mode?:(
 

szymczyk

macrumors regular
Mar 5, 2006
187
17
To the left of the variable list is the call stack. You should be able to see the function that generated the assembly language. Click on that function to go the function in the editor. Xcode does not automatically take you to the line of code that caused an error.

If you don't see any meaningful function names in the call stack, you may not have Xcode set up for debugging. Xcode has two different build configurations for each target: debug and release. Choose Project > Set Active Build Configuration > Debug. If you have an older version of Xcode, Xcode calls the build configurations development and deployment instead of debug and release. In this case you want the development build configuration. Using the debug build configuration gives you higher-level debugging.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
szymczyk said:
Xcode does not automatically take you to the line of code that caused an error.
Sometimes it does, actually (sometimes it will even highlight the line, sometimes not). I have yet to figure out what causes it to do this seemingly at random. Also, you will not be able to see any of your related methods shown in the call stack if the error was generated in a method in another process or thread. For example, your application might be playing a movie or a song. If the error occurs in a separate QuickTime or CoreAudio render thread (even one initiated by your application), you won't see any of your own code.

You can also set breakpoints by clicking on a line number on the left of your code pane. When running the debugger, the application will pause at the breakpoint where you can examine the state of your application (all the objects and variables) at that point, and also step over code line by line to watch what changes in detail.
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
jamdr said:
Thanks for the reply. I see the debug mode, but I still don't get it. If I run my code in the debugger and an error occurs, I just see a window pop up full of assembly code. So the error occurred at 0xfffeff20 <+0032> lwz r11,0(r2). Is there a way to get a little more high level than that? Also is there a way to see what the current values of local variables are? I see a memory window, but again it's just registers and hex values. Is there no higher-level debug mode?:(

Either the error occurred in some piece of code outside of your project, or you're not looking at the right window pane. There should be options to show local variables and single-step through source code.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
jamdr said:
Thanks for the reply. I see the debug mode, but I still don't get it. If I run my code in the debugger and an error occurs, I just see a window pop up full of assembly code. So the error occurred at 0xfffeff20 <+0032> lwz r11,0(r2). Is there a way to get a little more high level than that? Also is there a way to see what the current values of local variables are? I see a memory window, but again it's just registers and hex values. Is there no higher-level debug mode?:(

Do you use an NSScanner object in your code? If so, put a breakpoint on this line (or a line previous to it) and debug. Then step over the line where you allocate/use the NSScanner, and see what happens.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
I'm new to Obj-C and when I tried to run my application I got this error in the run log:

2006-04-30 01:01:18.940 MyProject[404] NSScanner: nil string argument

I don't really understand what that means because I don't know where in my code the error occurred. Is one of those numbers a line number? XCode's debugger seems really unintuitive. I'm used to eclipse, where if an error occurs you can jump right to the part of your code where the problem is. How can I do this in XCode?

By the way, anything that is in the run log will be there because the developer put an "NSLog" statement into their code which was executed, and that NSLog statement will put whatever the developer wanted into the code. It is not an error. If you have an error where the program would crash, and you run under the debugger, then XCode will go to the place of the crash.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.