Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Meet Objects Creating Classes

2 errors on line 6 PezDispenser

I can't find the errors on: the line that makes the new PEZ

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();
        System.out.printf("The dispenser is %s %n",
                                            dispenser.characterName);
  }

}

5 Answers

Hi William,

I can't see the errors either - what errors are you getting and can you post your code from the PezDispenser class too? I'm wondering if there's a little typo in there, perhaps.

Steve.

Seth Kroger
Seth Kroger
56,407 Points

It would also help to know what the errors are and whether they are occurring in the PezDispenser.java file instead of the Example.java file.

Clicked send too early - yes, the source of the errors would interesting too. The message should show us that.

Seth Kroger
Seth Kroger
56,407 Points

I hit send a little early too...

I'm always on a tablet in the evening - 23:00 here now - and it has the most sensitive "you touched the screen" reflex so it sends stuff that I've rarely finished typing. I should drag the laptop down from the office but that'd just keep me working until far too late! I don't have my work tools on the tablet so I can just browse and watch some tv with my guitar in hand, chilling. (Radiohead's tonight's musical challenge!)

Thanks Steve, I just realized that the Pez class is in a file spelled PezDispensor.java for unknown reasons.

That shouldn't make any difference - it didn't in my code, but as long as you got going again, that's great. It might have been a recompile that fixed it; the file name seems less critical. Doesn't matter - as long as you're on your way. :+1:

Here's the PEZ. I've been trying to copy and paste the errors but somehow it won't let me.

class PezDispenser {
    String characterName = "Yoda";
}

Here's the errors. It finally allowed me to copy and paste.

Picked up JAVA_TOOL_OPTIONS: -Xmx128m                                                    
Picked up _JAVA_OPTIONS: -Xmx128m                                                        
Example.java:6: error: cannot find symbol                                                
                PezDispenser dispenser = new PezDispenser();                             
                ^                                                                        
  symbol:   class PezDispenser                                                           
  location: class Example                                                                
Example.java:6: error: cannot find symbol                                                
                PezDispenser dispenser = new PezDispenser();                             
                                             ^                                           
  symbol:   class PezDispenser                                                           
  location: class Example                                                                
2 errors          

Is your Pez class in a file called PezDispenser.java?

I tried it with a different file name - it still worked. Have you saved everything and recompiled your code?

You should have no red dots in the tabs at the top of the Workspace and you'll need to run javac Example.java every time you've saved a change else it'll not recognise the changes.

Daniel Hunter
Daniel Hunter
4,622 Points

I had the same 2 errors on line 6, I just realised that I misspelled the file name for PezDispenser.java, I corrected it and re-run the program then it worked.