?
Solved

Neatbeans Debug, track changes to a variable

Posted on 2010-09-08
10
Medium Priority
?
904 Views
Last Modified: 2013-12-14
I want to see a varaible change.  I right click and say 'add to watch' and only shows the current state it does not track its history of change?  Is there a debug tool that can do this and can work with NetBeans?
0
Comment
Question by:RichardSDetsch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33632947
I have never come across a tool like that since the watch is usually to monitor the variable as you are stepping through code

why dont you try this, in the setter of that variable (assuming its a class variable), why dont you log the value being passed in.

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33632953
in case you are not familiar with the logger in Java like log4j. you do not have to worry about removing logging code then when app goes live.
0
 

Author Comment

by:RichardSDetsch
ID: 33633035
icecream flavs:
The variable is a private data member of a class of type double and my constructor sets it, but somehow by the time it gets to the classes toString method it gets changed to 0.0.   I am unfamiliar with this operation.   So if my class is below what would I do to log the value as being passed in its setter?

public class Class{
   private double trackVar;

   public Class(double trackVar){}

    public String toString(){print trackVar}

    public setTrackVar(double d){trackVar =d}
}

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Accepted Solution

by:
rockiroads earned 900 total points
ID: 33633065
add the logging in setTrackVar

public setTrackVar(double d) {
    LOG LINE HERE
    trackVar =d
}

if you are sure your constructor is setting it a value (which I assume is non zero) then something must be calling it. Tracing helps but you could put a breakpoint on the line trackVar = d then run your code in debug. Once it stops at that breakpoint you can check out the stack to see where it was called from
0
 

Author Comment

by:RichardSDetsch
ID: 33633078
I am very new to this.  I will try this when I go to work tomorrow.  Thanks so much.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33633167
No problems.

If you dont want logging at this stage, just dump it using

System.out.println("Passed in value is " + d);

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33633170
if u got time, have a look at log4j. http://www.vipan.com/htdocs/log4jhelp.html
0
 
LVL 6

Expert Comment

by:__geof__
ID: 33634712
Can we get a look on your constructor and how it is called. It may be conversion problems i.e. if you try to set an int somewhere it won't do (like double = int/int doesn't work)
0
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 600 total points
ID: 33636871
Check your constructor and make sure you are setting this.trackVar and not just trackVar.  The 0.0 value is the default for doubles so it sounds like it isn't actually getting set in your constructor.
public Constructor(double trackVar) {
    // BAD -- Sets trackVar parameter, not class attribute
    trackVar = trackVar;

    // GOOD -- Sets trackVar class attribute to value of parameter
    this.trackVar = trackVar;
}

Open in new window

0
 

Author Closing Comment

by:RichardSDetsch
ID: 33657442
These solutions are good practive.  Where you have a private variable that can only be acesses by setter functions.  But they do not track who called the setter and when.  
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question