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 Annotations Using Java's Built-In Annotations The @Override Annotation

Sven Hecker
Sven Hecker
748 Points

Cannot find symbol

If i try to run the exact same code as shown in the vid at min 3:32 i got an error saying

com/teamtreehouse/override/Main.java:6: error: cannot find symbol
        System.out.println(mycheese);
                           ^
   symbol:   variable mycheese
   location: class Main
   1 error

My SDK ist set to "temurin-17" and Compiler output is defined too.

1 Answer

Steven Parker
Steven Parker
231,269 Points

All this error is saying is that there is an attempt to reference "mycheese" but that it has not been declared. To help identify the actual issue, we'd need to see the rest of the code, or you could share a link to a workspace snapshot.

Sven Hecker
Sven Hecker
748 Points

Hi, thank you for your reply. Here is what my Main.java looks like:

package com.teamtreehouse.override;

public class Main {
    public static void main(String[] args) {
        Cheese myCheese = new Cheese();
        System.out.println(mycheese);
    }
}

and my Cheese.java:

package com.teamtreehouse.override;

public class Cheese {
    public String toString(String something){
        return "String cheese!";
    }
}

If the problem is a missing reference, why does it work in the video though?

Steven Parker
Steven Parker
231,269 Points

It's a spelling issue. The symbol previously declared is "myCheese" (with a capital "C"), but the undefined reference is to "mycheese" (all lower case).

The working code in the video has a reference to "myCheese", spelled the same as it was declared.