Java Android refer to a non-final answer inside an inner class
<p>Yes, I have seen the other questions and i have read through them and i have tried to understand it but i think i am struggling to make it work in my scenario.</p>

<pre><code>Random rand = new Random();
int randNumber;
long chosenNumber;
String answer;
while (questionCount &lt; 3) {
//---get all titles---
db.open();
Cursor c = db.getAllTitles();
if (c.moveToFirst())
{
    do {          
        DisplayTitle(c);
    } while (c.moveToNext());
}
db.close();

//---pick a question---
db.open();
randNumber = rand.nextInt(3);
chosenNumber = (long) randNumber;

String questionPrompt = db.pickQuestion(chosenNumber);
while (questionPrompt == null)
{
    randNumber = rand.nextInt(3);
    chosenNumber = (long) randNumber;
    questionPrompt = db.pickQuestion(chosenNumber);
}

answer = db.pickQuestion(chosenNumber);
question.setText(questionPrompt);
db.close();

btnclickme.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        String str = txtname.getText().toString();
            if (str.equalsIgnoreCase(answer)) {
                Toast.makeText(getBaseContext(), "That is correct!", Toast.LENGTH_SHORT).show();
        }

            else
                Toast.makeText(getBaseContext(), "That is incorrect, try again.", Toast.LENGTH_SHORT).show();
        }
    }); 
</code></pre>

<p>I get the error cannot refer to a non-final variable answer... whatever when i am trying to check if the text from the user is equal to the string answer. My question is, how do i make it so i can edit the answer (i am going to continually call different questions in like put this in a while loop and change the answer over and over) so every time i make the answer a final, it does not change for the next question. Do i have to create a variable for every question? help!</p>
