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

Non-Static Methods.

Here is the error: ./GoKart.java:17: error: non-static method charge() cannot be referenced from a static context while(GoKart.charge()) { ^ ./GoKart.java:17: error: incompatible types: void cannot be converted to boolean while(GoKart.charge()) { ^ ./GoKart.java:20: error: non-static method isFullyCharged() cannot be referenced from a static context if(GoKart.isFullyCharged()) { ^ 3 errors

Also STatic context. Python wouldn't say that.

1 Answer

Hi Thomas,

Static methods can be accessed straight off the class; no instance of that class is needed.

You have tried to use charge and isFullyCharged straight off the class:

while(GoKart.charge()) /// GoKart class, not instance
 if(GoKart.isFullyCharged()) // same again

You don't need to reference the GoKart class directly inside itself. You are trying to use instance method isFullyCharged() inside charge() to see if the instance using this functionality has a complete charge. Here:

  public void charge() {
    while(!isFullyCharged()){
      mBarsCount++;
    }
  }

You are modifying the existing charge method. Inside it, you test if !isFullyCharged() returns false (not! true) and if it does, you increment mBarsCount. You don't need to specify the class as you are working inside it.

I hope that makes sense.

Steve.