In xcode during debugging, it is possible to print out the value of a variable at that particular stage. I was just wondering if there is a similar function in Netbeans? If not, what Java IDE does?
2 Answers
Have you tried the following methods:
Put a breakpoint on the line where you want to see the value. Run the debugger on that file and switch to the 'Variables' tab (Window > Debugger > Variables
). This will display the values of your variables at that breakpoint. These rows might also have children rows - eg. If there was an array named myArray
, you can click on the +
symbol next to it to see each elements value.
You can also evaluate conditionals by going 'Debug' > 'Evaluate Expression'
. For example, in the iterating loop over 'myArray', you could enter myArray[2] == 5
and click the green ->
arrow to evaluate this. If the value of that element was 5, this would indicate the expression, type (boolean
in this example), and output of that test.
OR
Insert your breakpoint wherever you'd like to monitor the variable.
Right-click the breakpoint and select 'Breakpoint > Properties'.
Set the suspend to "No thread (continue)".
Then just fill in the corresponding field with the format of
{=<variable name>}
. So, for example entering: "myVar value @ L30 is: {=myVar}
" will output "myVar value @ L30 is: 1
" to the debugger console.
You shouldn't need to recompile. Just run under the debugger and switch to the console output.

- 19,824
- 17
- 99
- 186

- 802
- 11
- 25
Set breakpoint and use the 'PO' keyword to print the variable.
ex: `NSString *string=@"String to print";` in your code
if want to print this string in debugging mode, just you need to put breakpoint in front of this line and type Po string
in log panel.

- 117
- 2
- 11
-
sorry, is this for netbeans or xcode? I'm actually asking if printing out variable values can be achieved in netbeans. But thanks for helping out! – Thor Aug 09 '16 at 01:02