Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out value of a variable during debugging in Netbeans?

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?

like image 205
Thor Avatar asked Jul 27 '16 03:07

Thor


People also ask

How do I view variable values in Netbeans debugger?

Generally, the pane underneath the code has some tabs - and one of them will say 'Variables'. Click on that tab and you will see variables and their values. You need to be actually running a debug session before the variables tab is available.

How do I see variable values in Visual Studio debugging?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do I open a variable in Netbeans?

Click on the "Watches" tab at the bottom. Now click on Run > New Watch at the top menu. Type in "name" to watch the name variable and press the OK button. After pressing enter you will notice that the name variable is in the Watches window.


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.

like image 186
cognophile Avatar answered Oct 22 '22 08:10

cognophile


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.

like image 35
Ajay.km Avatar answered Oct 22 '22 07:10

Ajay.km