Reputation: 37
I have problems with multiple conditions in a java while
loop. I am trying to put conditions as not equal as null, but android studio says that &&
cannot be applied to boolean. Any help is appreciated!
I am trying to do this:
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);
}
Upvotes: 0
Views: 487
Reputation: 32
You have got a typo in a part of the while-condition:
(answerOne = reader.readLine()) !null)
should be:
(answerOne = reader.readLine()) != null)
Maybe that solves your issue?
Upvotes: 2
Reputation: 178263
You have malformed conditions. This includes a missing opening parenthesis (
, a !
operator where a !=
operator makes sense, a missing closing parenthesis )
, and misspelling "answer" on 2 variables in the conditions.
Replace
(answerOne = reader.readLine()) !null)
with
((answerOne = reader.readLine()) != null) // Two ( at beginning; !=
Replace
( anwserThree= reader.readLine()) != null)
with
((answerThree = reader.readLine()) != null) // Two ( at beginning; spelling
Replace
( (anwserFour= reader.readLine()) != null)
with
((answerFour= reader.readLine()) != null)) // Spelling; Two ) at end
Upvotes: 3