I have an activity with some final variables. I extracted their values (let's assume they're all Strings) into a resources file.
If I directly assign them on the instantiation (as following):
private final String PREFERENCE_NAME = getResources().getString(R.string.preference_name);
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
Cannot assign value to final variable 'PREFERENCE_NAME'
In this case I think the best thing to do it just make multiple calls to the resources. You still only have to change the value in one place and the call to
getResources() isn't an expensive one.