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 Java Objects Harnessing the Power of Objects Filling the Dispenser

James Stride
PLUS
James Stride
Courses Plus Student 621 Points

not-static variable MAX_PEZ cannot be referenced from a static context PezDispenser.MAX_PEZ);

Cant figure out why Im getting this error since its exactly like Craigs code.
Example.java:7:error: non-static variable MAX_PEZ cannot be referenced from a static context PezDispenser.MAX_PEZ); ^

Madhuri Charugundla
Madhuri Charugundla
2,383 Points

You forgot to mention the keyword static before the constant variable MAX_PEZ. If you want the constant to be accessed from the class instead of object scope, then you have to mention static keyword. public static final int MAX_PEZ = 12;

2 Answers

James Stride
PLUS
James Stride
Courses Plus Student 621 Points

Thank you so much Madhuri ! I laughed about it once I saw that mistake.

Uris Nicolas
Uris Nicolas
1,906 Points

Thank you very much !!