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

Java

someone explain to me why this doesnt work

//example file//
public class Example {
   String Container; 
    public static void main(String[] args) {
        // Your amazing code goes here...
        System.out.println("We are making new containers");
        Container container = new Container("Yoda");
        System.out.printf("The container character is %s\n", container.getCharacterName());
        if (container.isEmpty()) {
          System.out.println("It is currently empty");
        }
      System.out.println("Loading...");
      container.load();
      if (!container.isEmpty()) {
        System.out.println("It is no longer empty");
      }
    }
}
//container file//
public class Container {
  public static final int MAX_BLOCKS = 12;
  private String mCharacterName;
  private int mBlockCount;

  public Container (String characterName) {
    mCharacterName = characterName;
    mBlockCount = 0;
  }

  public void load() {
    mBlockCount = MAX_BLOCKS;
  }

  public String getCharacterName() {
    return mCharacterName;
  }
}

and the error messages as follows

Example.java:9: error: cannot find symbol
if (container.isEmpty()) {
^
symbol: method isEmpty()
location: variable container of type Container
Example.java:14: error: cannot find symbol
if (!container.isEmpty()) {
^
symbol: method isEmpty()
location: variable container of type Container
2 errors

1 Answer

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

That message says there is no isEmpty method in the container class. I don't see one either. ;)

thanks for taking time to help me out. must have got deleted somewhere in there. java is definitely a lot more detail oriented than html or css

 public boolean isEmpty() {
    return mBlockCount == 0;
  }