In my Android app, I've created the file app/src/main/res/values/integers.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="server_port">8080</integer>
</resources>
I then have
public class MyApplication extends Application {
final MyServer server = new MyServer(R.integer.server_port);
}
However, when the app launches, a log statement reveals the value (i.e., R.integer.server_port) to be 2131296322.
Why is the value being garbled? Is that not how integer resources are supposed to be implemented?
R.integer.server_portgives the resource ID of the integer, not the integer itself. In order to get the actual integer, you have to dogetResources().getInteger(R.integer.server_port). However, this requires some modification to your original code as the resources won't have been set up by the timeMyApplicationis instantiated. Instead, you can doOf course,
serverwon't befinalanymore. You can refactor to