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 trialDylan Carter
4,780 Pointsjava-repl: ERROR: cannot find symbol (isEmpty method)
My code:
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;
}
}
repl loaded file no problem, it declared pd as the type of pez no problem, then when I try to use the isEmpty helper method (typed in: pd.isEmpty();) it says error cannot find symbol and has the arrow pointing to the period...
ive troubleshooted but cant figure it out, any ideas?
the same thing done with the load method works fine.
all of my work is saved, ive tried restarting repl.
5 Answers
r h
68,552 PointsI'm pretty sure you can't pump all this code into the repl. I did something like entering it line by line, and it did say "created PezDispenser" but the only way to actually make a PezDispenser is with the command "PezDispenser pd = new PezDispenser("name"); For something as complex as a class, I think it's better that you save it as a .java file and work from the command line to compile it and forget about the repl. For example, make a file called PezDispenser.java and have in it:
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; }
public static void main(String[] args) {
PezDispenser pd = new PezDispenser("Batman");
System.out.println(pd.isEmpty());
}
}
Then go to your folder in command line and type "javac PezDispenser.java && java PezDispenser"
Dylan Carter
4,780 Pointssmh no I was just showing you what my code was....I typed in as he typed in the the video into repl
Louis Mott
1,923 PointsI'm having the exact problem and have had A LOT of problems with repl that other people say don't exist for them......I'm typing into repl pd.isEmpty(); same as in video and "error: cannot find symbol" i have also tried pd.isEmpty() and same result. I hope someone at TeamTreeHouse can accurately tell us if it is a problem with repl or what we are typing in.
Jason Anello
Courses Plus Student 94,610 PointsHi Louis,
Did you save the java file after adding the isEmpty() method?
Jason Anello
Courses Plus Student 94,610 PointsHi Dylan,
I've tried your exact code and it worked for me as shown in the video.
Can you try again? If you get an error again then copy and paste in what you're seeing in the console.
Are you sure you typed isEmpty
exactly with an uppercase 'E'?
Did you save your java file after adding the isEmpty
method?
Benjamin Gooch
20,367 PointsI also gave your code a whirl and had no problems with it. I'm working in Chrome, how about you? I'm not sure if maybe the browser used might cause issues, as I've only tested it in Chrome.
Dylan Carter
4,780 PointsDylan Carter
4,780 Pointsyeah it ended up working I have no idea what the problem was it just didn't want to work for some reason I didn't change anything.