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 trialSiddesh Gannu
3,565 PointsError: Cannot find Symbol
I'm not sure what my error here is saying. I did exactly what Craig explained in the video but I here is my code: 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("Arnold Schwarchnagger"); System.out.printf("The dispenser is %s %n", dispenser.getCharName()); String previousHead = swapHead("T-850 Model Terminator"); System.out.printf("Head was %s but now its %s", previousHead, dispenser.getCharName()); }
}
class PezDispenser { //private String pezHead; private String charaName;
public PezDispenser(String charaName) { this.charaName = charaName; }
public String getCharName() { return charaName; }
public String swapHead(String charaName){ String OriginalHead = this.charaName; this.charaName = charaName; return OriginalHead; } }
The error I get says:
error: cannot find symbol String previousHead = swapHead("T-850 Model Terminator");
symbol: method swapHead(String) location: class Example 1 error
2 Answers
Florian Stegemann
Full Stack JavaScript Techdegree Student 22,660 PointsHi, your swapHead
method is part of your PezDispenser
class, which means you have to call it on an instance of that class like this:
String previousHead = dispenser.swapHead("T-850 Model Terminator");
Also, you can embedd your code into your question and make it much more readable by putting three backticks (```) in front and after the code.
Siddesh Gannu
3,565 PointsOMG Thank you so much! Appreciate the help!
Jack Cummins
17,417 PointsJack Cummins
17,417 PointsSo, what does the Cannot find symbol error mean?