I have tried various ways asked and answered here about this with no luck, such as: android how to use string resource in a java class
In an android project I have an app class named configuration, where several static variables are stored and used in my activities etc.
For a
public static final String MYVARIABLE
I want to load a string value depending on localised language from
values/strings.xml
I have tried importing:
import com.myappdomain.R
Then to get the string
context.getString(R.string.my_string_in_values_xml)
so that:
String FORMYVARIABLE = context.getString(R.string.my_string_in_values_xml);
Also I have tried:
String FORMYVARIABLE =
getResources().getString(R.string.my_string_in_values_xml);
apk compiles without error, but the string is not passed in the java class producing Fatal exception, in all the java activities that utilise the static string.
Any pointers? I dont want to use extra configuration locales etc in my class just to set a string that already exists in several languages in res/values/strings.xml unless there is no other way because I want to add/delete/edit them from there.