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
David Hinton
3,070 PointsCreating Classes | Java Objects
Hi I am on the creating Classes section on Java Objects and have hit a problem.
This is my error :
Example.java:8: error: cannot find symbol
dispenser.mCharacterName());
^
symbol: method mCharacterName()
location: variable dispenser of type PezDispenser
1 error
This is my code:
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a pez dispenser.");
PezDispenser dispenser = new PezDispenser();
System.out.printf("The dispenser Character is %s\n",
dispenser.mCharacterName());
} }
And my Dispenser file code:
public class PezDispenser{ public String mcCharacterName = "Yoda"; }
1 Answer
Jeremy Hill
29,567 PointsI would do your class PezDispenser like this:
public class PezDispenser{
private String name = "Yoda";
public String mcCharacterName(){
return name;
}
}
You can do it a number of ways but watch your spelling- I noticed that your mcCharacterName() was missing a 'c' in your printf statement.