我将它设为计时器,这使我每次用户撰写一个单词时都会检查正确的答案,这样如果用户提交了正确的答案,它就可以正常工作,但是当我为其他错误答案进行测试时,它无法正常工作和app崩溃了,
请帮助我,我想检查是否回答错误
//to check the whole answer
final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//answer button get text to string
final StringBuilder str = new StringBuilder();
for (int i = 0; i < btnanswer.length; i++) {
str.append(String.valueOf(btnanswer[i].getText()));
Log.d("asdf", "run: " + str);
gamefinished = true;
}
//check answer button with the button
if (answer.toLowerCase().equals(String.valueOf(str).toLowerCase())) {
startActivity(new
Intent(MainActivity.this,SecondActivity.class));
timer.cancel();
}
}
}, 0, 10);