我不断收到上面的错误消息与下面的IF语句。任何帮助表示赞赏。运算符||是未定义的参数类型(s)布尔,字符串
public void sendMessage(View button) {
String mName = Name.getText().toString();
String mGuess = Guess.getText().toString();
if (mGuess != "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9" || "10") {
Toast.makeText(MainActivity.this,
"The number you entered was invalid. Please try again.", Toast.LENGTH_LONG).show();
}
非常好,彻底的答案。另外,在存在大量字符串的情况下,“HashSet”或类似的可能是更有效的选择。 – 2013-03-10 01:41:12
@JeremyRoman - 好点。我认为[@assylias](http://stackoverflow.com/a/15317932/535871)提出了这个建议。 – 2013-03-10 01:42:48
确实。另外,这个数据结构永远不会改变,而且应该是该类的“静态final”成员。 – 2013-03-10 01:44:14