• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Instance Variable Values Not Updating  RSS feed

 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I have a JavaFX gui that is creating a new instance of data calculation to graph in a chart; however, the data is not updating each time the Platform.runLater() feature executes. Each time an event occurs, a new instance with the same variable name occurs. I use to get methods to retrieve the data I want, so shouldn't the values update each time the new instance is created?
This is a very condensed version of what happens with the event, but this is what is not working correctly.

Event:

Class constructor :
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Where are the variables in the method calls getting a value?
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have several methods that all return the desired value. They all produce the correct results. It is just a matter of passing that information to my JavaFX program to use the data to graph it. My question is why doesn't the new instance of the value assign new values to the elevation and azimuth variables, so that each time I call the get methods I will have a new variable to display on my graph. Shouldn't each iteration of solarData = new SolarTracker() create a new instance of data?
 
Paul Clapham
Sheriff
Posts: 22831
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek Smiths wrote:My question is why doesn't the new instance of the value assign new values to the elevation and azimuth variables...


I think your question could do with a bit of clarification. For example that statement: what "value" is that, and what is a "new instance" of the value, and why should it be assigning new values to some variables?
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My SolarTracker class is created to find the path of the Sun. It contains several methods some of which find the declination and hourangle. The two values that I need, the elevation and azimuth angles are both needed to display the path of the Sun on an XYChart. It was my impression that each time, even within a loop, an instantiation can be overwritten or assigned new values -- in this case elevation and azimuth. Each of the methods should produce new results since they involve a new instance in time. Inside the class constructor, the methods shown above will execute and produce new results assigning those return values to the variables you see above. After the new instance, I use two get methods to retrieve those values to be displayed as x and y values in my chart. Hopefully this is a little more clear -- me being lazy. :/
This code exist within a listener event:
 
Paul Clapham
Sheriff
Posts: 22831
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so you keep creating new SolarTracker objects. And for some reason you expect the getElevation() and getAzimuth() methods of two different SolarTracker objects to return different values. Do I have this right? Because I don't see why they should since the constructor doesn't have any parameters to impart differences to the two objects.

(And I wouldn't attribute the lack of clarity to any laziness on your part. It's mostly that you're using non-standard terminology.)
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. I don't understand why the constructor needs to impart any differences. The constructor includes both methods to execute and return their respective values. Then I use the instance variable to retrieve both those values. What am I missing? I don't understand why I can't assign the values within the constructor and then use the get methods...? Is the only way to create an two instances and then call each method (elevation and azimuth)?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would imagine the problem is the variables dcLat, declination and hourAngle contain the same values each time you create an instance of SolarTracker. BTW Where are these variable declared and assigned values?
I suggest you modify your code to pass in these values as parameters to the constructor.
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not the case. Yes, dcLat is a constant, but declination and hourAngle are continuously changing. All of the values are declared inside the constructor except for dcLat, elevation, and azimuth. This was all within a main method when I first wrote the program, but I was hoping to just be able to execute this sequence within the constructor.

public SolarTracker() throws IOException {
localTime = localTime.now();
int day = dayOfYear();
double equationOfTime = equationOfTime(day);
double lstm = localTimeMeridian();
double lst = localSolarTime(equationOfTime, dcLong, lstm);
double declination = declination(day);
double hourAngle = hourAngle(lst);
elevation = elevation(dcLat, declination, hourAngle);
double zenith = zenith(dcLat, declination, hourAngle);
azimuth = azimuth(dcLong, declination, zenith, hourAngle);

}
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason that this is not working and is this just bad practice in general?
 
Paul Clapham
Sheriff
Posts: 22831
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We still don't have enough information. Now we have more information about what's actually in the constructor, but there's still plenty of unknowns. For example we have this code:



which you might think produces different results based on the current date and time, but it would be necessary to look at those methods to see what they really do. Likewise there's this:



which looks like it might need to use the localTime variable, but maybe it doesn't.

And is "dcLong" a constant? One might assume it is, given that you said that "dcLat" was a constant; but if so how does it get into the SolarTracker class? Maybe it's a final static variable? Or maybe not...
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derek you have been posting here long enough now to know you should use code tags when posting code, please do so in future. Also when posting a snippet of code, such as the constructor in this case, please don't leave out a load of lines without some notes to so say as it just causes confusion which wastes our time and doesn't help you to get an answer.

As to your problem I suggest you pepper the constructor with print statements outputting the values of all those variables so you can see if values are changing as you assuming they are.
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for all of your help in fixing this problem. I did not mean to waste anybody's time and usually make complete posts -- finals week has gotten best of me.

Anyways, I've tested all the outputs (just as Tony mentioned) and the values are more or less correct (good enough for me), nevertheless, the instance values assigned to the variables inside the constructor should still be passed to the other class using a couple accessor methods (getElevation/getAzimuth). The getAzimuth data is working, but the elevation data is not.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, on re-reading my last post it sounded a lot harsher than I intended it to.

If one method is working and the other isn't I'd check through the code to make sure you aren't accidentally changing one of the values. BTW any values that you set in the constructor and should never change after that should be declared as final so you can't accidentally overwrite their values. But you'll need to post all the relevant code if we are to help without guessing at solutions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!