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

Can not create an object.

public class PezDispenser{
 public static final int MAX_PEZ = 10;
 private String mCharacterName;
 private mPezCount;

 public PezDispenser(String characterName) {
  mCharacterName = characterName;
  mPezCount = 0;
 }

 public isEmpty() {
  return mPezCount == 0;
 }

 public void load() {
  mPezCount = MAX_PEZ;
 }
}

here is what i'm typing to the java repl:

java> PezDispenser pd = PezDispenser("Yoda");

here is what i get:

java.util.NoSuchElementException 

3 Answers

Rebecca Rich is right - currently you're referring to PezDispenser("Yoda"), which would need to be a method returning an object of PezDispenser to make this work. If you're using 'new', you create an instance of this class (the object we need) and return it into pd.

Hope I explained it not too confusingly.

kind regards, Michael

Since you're trying your program in the REPL, did you load it? I think the Syntax was ":load [filename].java" while you're in REPL. The NoSuchElementException is hinting that something you wanted him to look for could not be found.

Hope this helps.

Kind regards, Michael

Try:

PezDispenser pd = new PezDispenser("Yoda");

that is the same thing i did.

I did what you siad but im still getting the same error.