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

Please help do not understand why i'm getting this error and code isn't running. I followed the example.

my class:

//class
public class GoKart{

  //fields
  private String mGoKartColor;

  //constructor
  public GoKart(String color){
  mGoKartColor = color;
  }

  //method
  public String getGoKartColor(){
  return mGoKartColor;
  }

}

Then on my example.java

public class Example {

    public static void main(String[] args) {
        // Your amazing code goes here...
        System.out.println("We are making a new go kart.");
      //ClassName __ instance variable __ new __ ClassName__
        GoKart kart = new GoKart("blue");
        System.out.printf("The color of the new kart is %s ", kart.getGoKartColor());
    }
}
and the error I keep on getting is:

location: class Example                                                             
Example.java:7: error: cannot find symbol                                             
        GoKart kart = new GoKart("blue");                                             
                          ^                                                           
  symbol:   class GoKart                                                              
  location: class Example                                                             
2 errors          

really do not understand why, I went over the examples DOEZENS of times and thought I understood this but I guess not.

I had to ask this again because im trying to follow along with the lesson and try out my code but doesn't seem to be working.

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Are these in two different files? What are their names? They need to match your class names.

This is a good point. Is your Java file name == "GoKart.java"?

Craig you're the man! finally worked. The name of the file where I created the class was PezDispenser.java. I thought I could experiment on the same file... Good to know that the class name needs to be the same name as the file name.

The instructions read:

Print out using System.out.printf the color of the new object, using the getColor method.

Use the getColor() method, not getGoKartColor(). This exercise is using its OWN GoKart class and testing against that one. That GoKart class does not have a getGoKartColor() method.

Also, there's no need to repeat the class name in your member variables and methods. For instance, on a radio, it's not the "radio volume." It's just volume. The same thing applies for objects in Java.

I really hope this helped!

It's not a challenge it's just on the workspace so I think I can use my own class and experiment rite? Other than that I can't find an issue.

Apologies. I didn't realize it wasn't for the challenge. In that case, hmmm...

No worries really appreciate the help!