Java error: int cannot be converted to boolean

Error reference

Java error: int cannot be converted to boolean

This page is part of Intro to Java with Greenfoot. It assumes you have reached lesson 2.3. Opening it is not counted against you and is not tracked as progress.

The message

incompatible types: int cannot be converted to boolean

What it actually means

Something that needed a true or false question was given a number or an instruction instead. In an if condition this almost always means = was typed where == was meant.

The usual causes

Ranked by how often each one turns out to be the answer. Work down the list.

  1. Using a single = inside an if: `if (score = 10)` instead of `if (score == 10)`.
  2. Using a number as a condition, such as `if (lives)` instead of `if (lives > 0)`.
  3. Assigning to a boolean from an int.

How to fix it

Look inside the parentheses of your if and count the equals signs. One means you are assigning; you almost certainly want two, which compares. If there is no equals sign at all, you may be using a number where a true or false question belongs.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]