Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Uriah Nevins
1,121 PointsIncompatible types error
This is the error: ./PezDispenser.java:11: error: incompatible types: int cannot be converted to boolean
return mPezCount = 0;
^
I Can't seem to figure out why this error is coming up. Here is my code:
//This is my Example.java file
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are a making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser("Bob.");
System.out.printf("The dispenser character is %s\n",
dispenser.getCharacterName());
if (dispenser.isEmpty()){
System.out.println("It is currently empty");
}
System.out.println("Loading...");
dispenser.load();
if (!dispenser.isEmpty()){
System.out.println("Still have some pez!");
}
}
}
//This is my PezDispenser file
public class PezDispenser {
public static final int MAX_PEZ = 12;
private String mCharacterName;
private int mPezCount;
public PezDispenser(String characterName){
mCharacterName = characterName;
mPezCount = 0;
}
public boolean isEmpty(){
return mPezCount = 0;
}
public void load(){
mPezCount = MAX_PEZ;
}
public String getCharacterName() {
return mCharacterName;
}
}
Any help would be greatly apreciated. Thanks!
2 Answers

jcorum
71,830 PointsYou say your isEmpty() method will return a boolean, but instead you are returning an int. The problem is that you used = instead of ==. So you are assigning 0 to mPezCount and then trying to return the 0. You need mPezCount == 0:
public boolean isEmpty(){
return mPezCount == 0;
}

jcorum
71,830 PointsIt's not unlikely, as I like Java and look especially for Java questions. And yes, I'm just one person!
Uriah Nevins
1,121 PointsUriah Nevins
1,121 PointsDuh... Thanks!
Uriah Nevins
1,121 PointsUriah Nevins
1,121 Pointsjcorum, I'm pretty sure you've answered one of my questions before.... if u are just one person.