0

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);
}
2
  • 1
    are you missing an = before your third null? Commented May 15, 2015 at 20:08
  • Learn to properly format your code first... Commented May 15, 2015 at 20:10

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

2

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.