Reputation: 746
This is my Config
class:
public class Config
{
public static final String urlApi = "http://127.0.0.1/api/";
}
Whenever I want to change the location, I have to change the value of this variable:
public class Config
{
public static final String urlApi = "http://192.168.50.101/api/";
}
In this case, the value is:
But in debugging mode I saw that "urlApi" has the old value, old IP address. Its weird. How do I fix it ?
Upvotes: 0
Views: 1013
Reputation: 746
I solved the problem. I go to "Clean project" and then again "Make Project", i think this is explanation.
Note: If a primitive type or a string is defined as a constant and the value is known at compile time, the compiler replaces the constant name everywhere in the code with its value. This is called a compile-time constant. If the value of the constant in the outside world changes (for example, if it is legislated that pi actually should be 3.975), you will need to recompile any classes that use this constant to get the current value.
Upvotes: 2
Reputation: 75
Take a look: http://www.tutorialspoint.com/java/java_nonaccess_modifiers.htm
There are the different Access Modifiers
Upvotes: 1
Reputation: 1454
You must change:
public class Config {
public static final String urlApi = "http://192.168.50.101/api/";
}
to:
public class Config {
public static String urlApi = "http://192.168.50.101/api/";
}
The final
keyword means that the String is a constant - not a variable. This is, it can't be changed. Removing final
will allow the String to be changed whenever you want as normal.
Upvotes: 0