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 Method Overloading

Michel Spaniolo
PLUS
Michel Spaniolo
Courses Plus Student 1,850 Points

Yes im having trouble compiling.Maybe a hint at what im doing wrong would and has helped

https://w.trhou.se/l8316r5n3u Im getting an error when compiling that references the dispenser but i dont see the problem if that is the problem

2 Answers

Steven Parker
Steven Parker
231,265 Points

The compiler tries to identify the problems and tell you in the error messages. Some examples:

  • error: non-static variable MAX_PEZ cannot be referenced from a static context
    So you need to add the "static" keyword where that variable is declared on line 2 of PezDispenser.java
  • Example.java:12: error: cannot find symbol dispenser.swapHead
    The "swapHead" method that was previously in PezDispenser.java in your previous question has been removed, but it is still being called on line 12 of Example.java. Either remove the call (as in the video), or put the method back.
  • Example.java:16: error: cannot find symbol dispense.isEmpty
    This time it's a spelling error with "dispense" instead of "dispenser"

The other errors are similar, either spelling or a call to a method that was removed. I bet you can find and correct the rest of them by using the error messages now.

Steven Parker
Steven Parker
231,265 Points

Remember to pay attention to the compiler error messages, they will attempt to show exactly where the error is.

The compiler now points to a "catch" statement that seems to have no corresponding "try" in the code.

Also, the "error: reached end of file while parsing" often indicates unmatched parentheses or braces, and in this case there seems to be no closing brace for the class itself.

Some of the spelling errors still need to be corrected.

And as long as you have compiler errors, running the program won't give you any useful information since you are running an old version (from the last successful compile).

Michel Spaniolo
PLUS
Michel Spaniolo
Courses Plus Student 1,850 Points

I cleared out the swapHead method and it says theres still 1 error..the code runs only 2 lines..https://w.trhou.se/rp9piy63ca