Before I ask, I've already looked at this post and tried all suggestions to no avail. My problem is that I can easily set a String using
getResources().getString(R.string.example)
within the onCreate method, but I want to set a public static final String to a value in string.xml using the same getResources() method. But, when I do this, I get a "Cannot make a static reference to the non-static method getResources() from the type ContextThemeWrapper". So I tried instantiating ContextThemeWrapper and also
this.getResources().getString(R.string.example)
which both clear the error, but both crash with a NullPointerException. Any solution to simply set a String from a resource would be much appreciated.
So far I have this:
public class MainActivity extends Activity {
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper();
public final String CYPHER = contextThemeWrapper.getResources().getString(R.string.cypher_txt);
public static final int LAYERS = 7;
public static final int FLIP = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String appName = getResources().getString(R.string.app_name);
Toast.makeText(this, "Welcome to " + appName, Toast.LENGTH_SHORT).show();
}