我在java while
循环中遇到多个条件的问题。我试图将条件设置为不等于null,但android studio表示&&
不能应用于布尔值。任何帮助表示赞赏!
我正在尝试这样做:
String question = null, answer = null, answerOne = null,
answerTwo = null, answerThree = null, answerFour = null;
while (((question = reader.readLine()) != null)
&& ((answer = reader.readLine()) != null)
&& (answerOne = reader.readLine()) !null)
&& ((answerTwo = reader.readLine()) != null)
&& (anwserThree = reader.readLine()) != null)
&& ((anwserFour = reader.readLine()) != null)) {
//reading some lines from resource file
Question q = new Question(question, answer, answerOne, answerTwo,
answerThree, answerFour);
mQuestions.add(q);
}
答案 0 :(得分:3)
你的情况不正常。这包括缺少左括号(
,!
运算符,!=
运算符有意义,缺少右括号)
,以及错误拼写“回答”2中的变量条件。
替换
(answerOne = reader.readLine()) !null)
与
((answerOne = reader.readLine()) != null) // Two ( at beginning; !=
替换
( anwserThree= reader.readLine()) != null)
与
((answerThree = reader.readLine()) != null) // Two ( at beginning; spelling
替换
( (anwserFour= reader.readLine()) != null)
与
((answerFour= reader.readLine()) != null)) // Spelling; Two ) at end
答案 1 :(得分:2)
你在这段时间内有一段错字:
(answerOne = reader.readLine()) !null)
应该是:
(answerOne = reader.readLine()) != null)
也许这可以解决你的问题?