You are not logged in.

#1 2009-04-06 17:06:12

estex198
Member
Registered: 2009-02-17
Posts: 39

java cannot find symbol [Color type]

/**
* Parked car class
* class properties are 
*  - Car Color
*  - Car Model
*  - Car Make
*  - License Number
*  - Number of minutes car has been parked
*/



public class ParkedCar {


// Field declarations for class ParkedCar

// declare color datatype (enum)


Color CarColor;

String  CarModel,
    CarMake,
    LicenseNumber;

double TimeParkedMinutes;



public ParkedCar() {
    CarColor = Color.NOTSPECIFIED;
    CarModel = "NOT SPECIFIED";
    CarMake = "NOT SPECIFIED";
    LicenseNumber = "NOT SPECIFIED";
    TimeParkedMinutes = 0.0;
} // end no arg constructor method for ParkedCar class



public ParkedCar(Color parkedColor, String parkedModel, String parkedMake, String parkedLicense, double parkedMinutes) {

    CarColor = parkedColor;
    CarModel = parkedModel;
    CarMake = parkedMake;
    LicenseNumber = parkedLicense;
    TimeParkedMinutes = parkedMinutes;

} // end constructor ParkedCar


public Color getColor() {
    return CarColor;
}

public String getModel() {
    return CarModel;
}

public String getMake() {
    return CarMake;
}

public String getLicenseNumber() {
    return LicenseNumber;
}

public double getTimeParkedMinutes() {
    return TimeParkedMinutes;
} 


} // end class ParkedCar

I keep getting this compilation error

ParkedCar.java:21: cannot find symbol

symbol  : class Color

location: class Color.ParkedCar

Color CarColor;

The enumerated data type Color is declared within a separate class file. This code will compile when Color is defined within this class. Seems that enums are somewhat of a strange breed. Any ideas?

Last edited by estex198 (2009-04-06 17:07:43)

Offline

#2 2009-04-06 21:08:13

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

Re: java cannot find symbol [Color type]

You have to import the color class.

Put "import java.awt.Color;" at the top of your file (without quotes).

Offline

#3 2009-04-07 17:35:39

drewbug01
Member
From: chicago
Registered: 2007-04-06
Posts: 85
Website

Re: java cannot find symbol [Color type]

I don't think that's what he's getting at here -- he doesn't want java.awt.Color. He mentioned that it is defined as an enum in a separate file.

This seems to be an issue of scope. Can you post how you defined the enum you're trying to access ?
Remember, while you may not need to import the Color class if it's defined in the same folder, you still have to worry about scope. Did you define the enum as "private"? Try defining it as "public", or at the very least "protected". The fact that it works when it is defined in the file screams scope errors.

Hope that helps!
-- Drew

Offline

#4 2009-04-08 13:13:29

estex198
Member
Registered: 2009-02-17
Posts: 39

Re: java cannot find symbol [Color type]

I defined it as...

public enum Colors { BLACK, BROWN, RED, ORANGE, YELLOW, WHITE }

Offline

#5 2009-04-08 14:06:46

estex198
Member
Registered: 2009-02-17
Posts: 39

Re: java cannot find symbol [Color type]

found some example code. I'm definately doing something wrong here. Do I need an import statement somewhere? I found some example code on a tutorial site. The enumerated data type Days is only accessible to members of EnumTest if its declaration is within the class EnumTest (as opposed to storing the enum declaration in its own .java file.

public class EnumTest {
  
               public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, 
    THURSDAY, FRIDAY, SATURDAY 
}
    Day day;

    public EnumTest(Day day) {
        this.day = day;
    }
    
    public void tellItLikeItIs() {
        switch (day) {
            case MONDAY: System.out.println("Mondays are bad.");
                         break;
                    
            case FRIDAY: System.out.println("Fridays are better.");
                         break;
                         
            case SATURDAY:
            case SUNDAY: System.out.println("Weekends are best.");
                         break;
                         
            default:     System.out.println("Midweek days are so-so.");
                         break;
        }
    }
    
    public static void main(String[] args) {
        EnumTest firstDay = new EnumTest(Day.MONDAY);
        firstDay.tellItLikeItIs();
        EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);
        thirdDay.tellItLikeItIs();
        EnumTest fifthDay = new EnumTest(Day.FRIDAY);
        fifthDay.tellItLikeItIs();
        EnumTest sixthDay = new EnumTest(Day.SATURDAY);
        sixthDay.tellItLikeItIs();
        EnumTest seventhDay = new EnumTest(Day.SUNDAY);
        seventhDay.tellItLikeItIs();
        
        
    }
}

If I were to store the enum declaration in its own file then it should look something like this(?):

       public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, 
    THURSDAY, FRIDAY, SATURDAY 
}

Thanks for your time.

Offline

#6 2009-04-08 16:05:13

Fainto
Member
From: NL, Canada
Registered: 2009-03-26
Posts: 3
Website

Re: java cannot find symbol [Color type]

You're using Color in the main class definition but the enum is called "Colors".

Should work if you make it:

public enum Color { BLACK, BROWN, RED, ORANGE, YELLOW, WHITE }

Copying your code, it wouldn't compile. It worked for me after I made that fix and called the file Colors.java. I make mistakes like this all the time, and they're hard to pick up on tongue.

Last edited by Fainto (2009-04-08 16:09:41)

Offline

Board footer

Powered by FluxBB