简体   繁体   中英

Problems with multiple conditions in while loop java

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);
}

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM