RichardSDetsch
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?
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.
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}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 you dont want logging at this stage, just dump it using
System.out.println("Passed
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.