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 trialMichael Stolp-Smith
4,855 PointsGetting two errors while compiling and I am not sure why. Syntax seems correct.
So far I have public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("we are making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser();
System.out.printf("The dispenser character is %s/n",
dispenser.mCharacterName);
}
}
which as far as I know should be working. The concepts here make sense, but I am getting a compiler error along the PezDispenser dispenser = new PezDispenser(); indicating a symbol not found on "PezDispenser" and "PezDispenser();"
if anyone could explain this to me that would be great.
5 Answers
Michael Stolp-Smith
4,855 PointsAnswer: I am dumb and capitalized the file extension (PezDispenser.Java as opposed to PezDispenser.java)
markmneimneh
14,132 PointsHello
I believe your error is here:
ystem.out.printf("The dispenser character is %s/n", dispenser.mCharacterName);
mCharacterName is generally a private attribute in a Class. To get ti it, you should be using a getter method instead. Please double check you class and use a gerrter method. It should be something like
dispenser.getCharacterName()
if this answers your question, please mark the question as answered.
Thanks
Michael Stolp-Smith
4,855 PointsI made this change in the document and it did not solve the issue.
As far as I can tell my syntax matches everything in the video and I am still getting compiler errors of "cannot find symbol". That line is also not indicated as an error line, and the video does make use of dispenser.mCharacterName and not dispenser.getCharacterName(). The errors come before that as well, so that seems to be unrelated.
Michael Stolp-Smith
4,855 Pointsnote that this is the first exercise and this should work using mCharacterName
Michael Stolp-Smith
4,855 PointsAlright, this is yet solved perfectly though I did work around it (with help from a friend) by adding the PezDispenser class directly to Example in one document, and also made PezDispenser static.
{
static class PezDispenser { private String mCharacterName;
public PezDispenser(String characterName){
mCharacterName = characterName;
}
public String getCharacterName(){
return mCharacterName;
}
} }
I am yet unsure why this doesn't work in the workspace across two files.
Blake Larson
13,014 PointsBlake Larson
13,014 PointsCould you add your PezDispenser class as well. You main method looks right.