user3552603
user3552603

Reputation:

Array filled with variables not updating

Easy question I guess the answer will be very simple.

CODE: init variables

public static float AGREE = 1;
public static float DISAGREE = 1;
float values[] = { AGREE, DISAGREE };

changing value of variables and then calling them:

AGREE = 10;
DISAGREE = 1;
Log.d("Agree or disagree pressed", "AgreeValue" + values[0] + " DisagreeValue" +   
values[1]);

When I logged out AGREE and DISAGREE value it was 10 and 1 but when I log values[0] and values [1] it logs out 1 and 1. It happens even if I call log right in onCreate method (so nothing before is executed). Why it is not updated?

Upvotes: 0

Views: 33

Answers (2)

shweta_jain
shweta_jain

Reputation: 453

You can't Change value of array once you initialized array.

Upvotes: 0

SacreDeveloper
SacreDeveloper

Reputation: 1251

The problem is when you change the variables, they are not the same which you added first in the float value[] array. Once you create an array, the array have his own vars.

you must change it directly with :

values[0] = 10;
values[1] = 1;

Upvotes: 1

Related Questions