R.string.XXX returns an int from strings.xml when I need a String

android, java, undefined

Solution

`R.string.*` is a reference to an int in R.java that points to your actual String.

Use `context.getResources().getString(R.string.*);` to get the actual String value.

Problem

This is sort of a continuation of this thread: Localizing strings in strings.xml gives NullPointerException This issue arose after going through and implementing the solution provided in that thread. The solution provided worked for instances like this: ``` loading = (TextView)findViewById(R.id.loading); loading.setText(R.string.loading); ``` This does not work for situations like below: ``` exodus.add(new Question(R.string.a, R.string.b, R.string.c, R.string.d, 0, R.string.e, -1, R.string.f)); ``` The error is `The constructor Question(int, int, int, int, int, int, int, int) is undefined`. The contructor for Question is supposed to be `Question(String, String, String, String, int, String, int, String)` but these: ``` R.string.X ``` are returning as ints instead of Strings. What can I do to fix this problem? And also, if you know, why is this method working for setting text of `TextView`s but not parameters in objects?

Original source

Related problems