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 Incrementing

Cannot find symbol

during this challenge, even if I type out what it is telling me to type out it will still say that it cannot find symbol. Please help.

Gavin Ralston
Gavin Ralston
28,770 Points

Could you post the code that you're putting in the challenge?

Also, if possible, try to get the exact error message from the "Preview" section if it's more than just a count of the errors.

there is the code,

public boolean charger() { boolean wasCharged = false; if (!isCharged()) { mBarsCount--; wasCharged = true; }
return wasCharged; } and here is the error ./GoKart.java:28: error: cannot find symbol if (!isCharged()) { ^ symbol: method isCharged() location: class GoKart 1 error

Gavin Ralston
Gavin Ralston
28,770 Points

I can't read the code very well because it's not formatted, but I think I see the issue:

In the challenge, the method name isn't "isCharged()" it's "isFullyCharged()" so the symbol (that's the variable name) isn't being found because it can't find an "isCharged()" method.

Hope that helps. Or the answer I provided. :)

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

Cannot find symbol means it cannot find the variable you're using.

In the case of this challenge, you can either store the result of the isFullyCharged() method directly in your while statement like:

while ( !isFullyCharged() ) {
    //do something...
}

Or if it helps you work it out, store the result in a variable and plug it in:

boolean full = isFullyCharged();

while (!full) {
 // do something
}

// when you exit the loop (finish charging) you'll do something else

To answer your comment on the original question, I think you'll want to use the defined method isFullyCharged() and not try to use isCharged() -- that method isn't defined, so it's a "symbol that can't be found" by the compiler. :)