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) Meet Objects Creating New Objects

What is wrong here?

I have been making a challenge "Creating new objects". Which mistake have I done? Here is what console says:

./Example.java:5: error: cannot find symbol
         mGoKartColor GoKart = new mGoKartColor ("red");
         ^
  symbol:   class mGoKartColor
  location: class Example
./Example.java:5: error: cannot find symbol
         mGoKartColor GoKart = new mGoKartColor ("red");
                                   ^
  symbol:   class mGoKartColor
  location: class Example
2 errors

Here is what I wrote:

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
         mGoKartColor GoKart = new mGoKartColor ("red");
        System.out.printf("The GoKart color is %s.", GoKart.getColor);

    }
}

4 Answers

Your error is telling you that mGoKartColor cannot be found. In other words, the class does not exist. As indicated in the challenge prompt, the class is called GoKart. In that case, you'd create a new instance of that class like so:

GoKart goKart = new GoKart("green"); // Pass in whatever color you prefer
Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Enej;

Isn't the object name we are trying to create GoKart and not mGoKartColor?

Post back if you are still stuck.

Ken

Thank you! I tried that and now, I've complited the challenge.

Thank you both for fixing that bug, but now there is one more error:

./Example.java:6: error: cannot find symbol
        System.out.printf("The GoKart color is %s.", GoKart.getColor);
                                                           ^
  symbol:   variable getColor
  location: class GoKart
1 error

Currently, the program looks like:

public class Example {
    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
         GoKart goKart = new GoKart ("red");
        System.out.printf("The GoKart color is %s.", GoKart.getColor);
    }
}

Hey Enej,

You access the getColor method like so:

System.out.printf(goKart.getColor());

In other words: objectName.methodName();

Using the string formatter, you can also do it this way:

System.out.printf("The color of the goKart is %s.", goKart.getColor());