gpt4 book ai didi

java - 调试时的值相同,但 if 语句中的值不同

转载 作者:行者123 更新时间:2023-12-02 11:16:41 24 4
gpt4 key购买 nike

我的 if 语句有问题。两个值 - 字符串,一个在类中通过 arrow 声明,另一个通过 radiobutton.gettext() 声明。在调试中我可以读取两个变量的值。它们是相同的,但如果声明说它们是不同的。您知道为什么会发生这种情况吗?

调试器: /image/jYrMV.jpg

获取rbAnswer:

private String mChoices [][] = {
/* #8 */ {"razgovor između pomoraca u karanteni i njihovih obitelji", "za osobno razmatranje i razgovor s duhovnikom"," "," "},

}

...

public String getChoice1(int a) {
String choice0 = mChoices[a][0];
return choice0;
}


public String getChoice2(int a) {
String choice1 = mChoices[a][1];
return choice1;
}

...

rbGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
String rbAnswer;

public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radiobtn1)
rbAnswer = "" + rb1.getText();
else if (checkedId == R.id.radiobtn2)
rbAnswer = "" + rb2.getText();
else if (checkedId == R.id.radiobtn3)
rbAnswer = "" + rb3.getText();
else if (checkedId == R.id.radiobtn4)
rbAnswer = "" + rb4.getText();

tTEST.setText(rbAnswer);
if (rbAnswer == mAnswer) {
varScoreTrue = varScoreTrue + 1;
updateScore(varScoreTrue);
obavijestTocno();
updateQuestion();

} else {
varScoreFlase = varScoreFlase + 1;
updateScore(varScoreFlase);
obavijestKrivo();
updateQuestion();
}



}

});

声明mAnswer:

private String mCorrectAnswers[] = {

...

/* #8 */ "za osobno razmatranje i razgovor s duhovnikom",


...
}

...

public String getCorrectAnswer(int a) {
String answer = mCorrectAnswers[a];
return answer;
}

...

mAnswer = mQuestionLibrary.getCorrectAnswer(mQuestionNumber);

最佳答案

您进行了错误的比较。

更改:

rbAnswer == mAnswer

rbAnswer.equals(mAnswer)

关于java - 调试时的值相同,但 if 语句中的值不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50220626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com