Link to home
Start Free TrialLog in
Avatar of RichardSDetsch
RichardSDetschFlag for United States of America

asked on

Neatbeans Debug, track changes to a variable

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?
Avatar of rockiroads
rockiroads
Flag of United States of America image

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.

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.
Avatar of RichardSDetsch

ASKER

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}
}

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am very new to this.  I will try this when I go to work tomorrow.  Thanks so much.
No problems.

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

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

if u got time, have a look at log4j. http://www.vipan.com/htdocs/log4jhelp.html
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)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.