I'm creating a quiz app, the link is link .
I'm trying to use getString(R.string.nome)
to migrate the strings of the java class and then I can use 2 languages.
In other places I was able to pull the strings and it works by showing the texts when I run the app on my phone, but the moment I try to use the string in the questions, the app just does not open anymore.
public class Questions {
public String mQuestions[] = {
// Funciona
"Pergunta número 1 xxxxxxx",
// NÃO FUNCIONA
getString(R.string.Q1_function_insulin),
};
/ = / = / = / =
Update:
I made the following changes and it did not work:
My MainActivity.java:
public class MainActivity extends AppCompatActivity {
Button answer1, answer2, answer3;
TextView score, question;
private Questions mQuestions;
private String mAnswer;
private int mScore = 0;
private int mQuestionsLength;
Random r;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mQuestions = new Questions(this);
mQuestionsLength = mQuestions.mQuestions.length;
r = new Random();
My other Questions.java file
import android.content.Context;
public class Questions extends MainActivity {
Context context;
public Questions(Context context)
{
this.context = context;
}
public String mQuestions[] = {
"Pergunta número 1 xxxxxxx",
context.getString(R.string.Q1_function_insulin),
"Outra Pergunta número 2",
};