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 (Retired) Harnessing the Power of Objects Methods and Constants

ERROR: cannot find symbol

java> PezDispenser pd = new PezDispenser("Yoda");

ERROR: cannot find symbol
symbol: class PezDispenser
location: interface Evaluation
PezDispenser method$am4d69u0i

7 Answers

Okay, your issue is that the method getCharacterName looks like it's commented out. Try putting that last bit on a new line, like this.

public class PezDispenser {

   public final int MAX_PEZ = 12;

   private String mCharacterName;

   public PezDispenser (String characterName){ mCharacterName = characterName; }

   public boolean isEmpty(){ boolean isActuallyEmpty = mPezCount == 0; return isActuallyEmpty; }

   //Creates a public class that gets the private object above. 


  // This was commented out
   public String getCharacterName() {
      return mCharacterName; 
   }

 }
Isaiah Wojciechowski
Isaiah Wojciechowski
3,163 Points

so I am getting the same error and i dont see what could be wrong with my code

public final int MAX_PEZ = 12; //common practice add 'm' prefix to the members of a class private String mCharacterName;

public PezDispenser(String characterName){ //initialization code mCharacterName = characterName; }

public String getCharacterName(){ return mCharacterName; } }

Two things to check are

1) Do you have a class named "PezDispenser" (Both does it exist, and is it spelled correctly?) 2) Is your constructor on PezDispenser written correctly?

It would definitely help if you posted your PezDispenser class code here, that helps with troubleshooting.

public class PezDispenser {

public final int MAX_PEZ = 12;

private String mCharacterName;

public PezDispenser (String characterName){ mCharacterName = characterName; }

public boolean isEmpty(){ boolean isActuallyEmpty = mPezCount == 0; return isActuallyEmpty; }

//Creates a public class that gets the private object above. public String getCharacterName() {

return mCharacterName; } }

Interesting. This class definition looks fine. How are you interacting with it? Could you post your code that's calling this?

sorry I am new to java so I don't know if I am posting the right there but this is the other part of it.

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("Yoda");
  System.out.printf("The dispenser character is %s \n", dispenser.getCharacterName());

}

}

Also I typed this in the console :

Loaded source file from PezDispenser.java
java> PezDispenser pd = new PezDispenser("Yoda");
ERROR: cannot find symbol
symbol: class PezDispenser
location: interface Evaluation
PezDispenser method$mlyj8ni9zqu3evgsr24t();
^
java>

Thanks a bunch. Is that not the right way to make comments in java?

Yes using the slash is the correct way, but you didn't give the method a new line, so the method header was actually getting commented out as well.

well thank you very much for all your help!