Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9300

Another Compiler Error

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From Novice <novice@example..com>
Newsgroups comp.lang.java.programmer
Subject Another Compiler Error
Date Sat, 29 Oct 2011 17:23:02 +0000 (UTC)
Organization Your Company
Lines 146
Message-ID <Xns9F8D88D6743B5jpnasty@94.75.214.39> (permalink)
NNTP-Posting-Host Yzqi07giy+IXRagYOPUEUQ.user.speranza.aioe.org
X-Complaints-To abuse@aioe.org
User-Agent Xnews/5.04.25
X-Antivirus-Status Clean
X-Notice Filtered by postfilter v. 0.8.2
X-Antivirus avast! (VPS 111029-0, 2011-10-29), Outbound message
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9300

Show key headers only | View raw


Can an enum make references to another enum? 

I'm trying to figure out a compiler error.

I have an enum called ColorPalette which references a second enum called 
ColorName. Here is a relevant excerpt from ColorName:

==============================================================
public enum ColorName {

	BLACK					(new Color(0, 0, 0)),
	WHITE					(new Color(255, 255, 255)),
	PALE_GRAY   			(new Color(204, 204, 204)),
	PALE_DULL_RED 			(new Color(255, 153, 153)),
        /* etc... */
	MEDIUM_FADED_RED		(new Color(255, 51, 51));

	private final Color color;
    /**
     * Constructor for enum ColorName.
     * 
     * @param color the color associated with the color name.
     */
    ColorName(Color color) {
        this.color = color;
    }

    public Color getColor() { return this.color; }
}

==============================================================

Here is an excerpt of ColorPalette which illustrates how I'm using 
ColorName:

==============================================================
public enum ColorPalette {

    /** Constant and data for BLUES color palette. */
    BLUES     	(ColorName.PALE_GRAY, ColorName.WHITE, ColorName.BLACK, 
ColorName.PALE_WEAK_BLUE, ColorName.PALE_DULL_BLUE, 
ColorName.MEDIUM_FADED_BLUE,  ColorName.PALE_DULL_ORANGE, 
ColorName.RED_RED_PINK),  
    
    /** Constant and data for REDS color palette. */
    REDS      	(ColorName.PALE_GRAY, ColorName.WHITE, ColorName.BLACK, 
ColorName.PALE_DULL_RED, ColorName.MEDIUM_FADED_RED, 
ColorName.DARK_FADED_RED, ColorName.PALE_DULL_TEAL, 
ColorName.SPRING_SPRING_GREEN),

        /* etc.... */

    /** The background color associated with a given color palette. */
    private final ColorName backgroundColorName;
    
    /** The light text color associated with a given color palette. */
    private final ColorName textLightColorName;
    
    /** The dark text color associated with a given color palette. */
    private final ColorName textDarkColorName;
    
    /** The light contrast color associated with a given color palette. 
*/
    private final ColorName contrastLightColorName;
    
    /** The medium contrast color associated with a given color palette. 
*/
    private final ColorName contrastMediumColorName;
    
    /** The dark contrast color associated with a given color palette. */
    private final ColorName contrastDarkColorName;
    
    /** The opposite color associated with a given color palette. */
    private final ColorName oppositeColorName;
    
    /** The clash color associated with a given color palette. */
    private final ColorName clashColorName;
    
    /**
     * Constructor for enum ColorPalette.
     * 
     * @param backgroundColor the background color associated with the 
color palette.
     * @param textLightColor the light text color associated with the 
color palette.
     * @param textDarkColor the dark text color associated with the color 
palette.
     * @param contrastLightColor the light contrast color associated with 
the color palette
     * @param contrastMediumColor the medium contrast color associated 
with the color palette.
     * @param contrastDarkColor the dark contrast color associated with 
the color palette.
     * @param oppositeColor the opposite color associated with the color 
palette.
     * @param clashColor the clash color associated with the color 
palette.
     */
    ColorPalette(ColorName backgroundColorName, ColorName 
textLightColorName, ColorName textDarkColorName, ColorName 
contrastLightColorName, ColorName contrastMediumColorName, ColorName 
contrastDarkColorName, ColorName oppositeColorName, ColorName 
clashColorName) {
        this.backgroundColorName = backgroundColorName;
        this.textLightColorName = textLightColorName;
        this.textDarkColorName = textDarkColorName;
        this.contrastLightColorName = contrastLightColorName;
        this.contrastMediumColorName = contrastMediumColorName;
        this.contrastDarkColorName = contrastDarkColorName;
        this.oppositeColorName = oppositeColorName;
        this.clashColorName = clashColorName;
    }

    /**
     * Gets the background color associated with a given ColorPalette.
     * 
     * @return the background color associated with a given ColorPalette.
     */
    public Color getBackgroundColor()   { return 
this.backgroundColorName.getColor(); }


    /**
     * Gets the light text color associated with a given ColorPalette.
     * 
     * @return the light text color associated with a given ColorPalette.
     */
    public Color getTextLightColor()   { return 
this.textLightColorName.getColor(); }

       /* etc... */

}
==============================================================

Every single reference to ColorName in ColorPalette is flagged with a 
compile error: "ColorName cannot be resolved to a variable" in the 
Constants section or "ColorName cannot be resolved to a type" elsewhere. 
One of the fixes is to import ColorName but when I try this, nothing 
happens, even though ColorPalette and ColorName reside in the same 
package and ColorName has no compile errors. 
 
What's going on here? I can't figure out why ColorName isn't "seen" by 
ColorPalette even though both are public and in the same package. 
-- 
Novice

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Another Compiler Error Novice <novice@example..com> - 2011-10-29 17:23 +0000
  Please ignore [was Another Compiler Error] Novice <novice@example..com> - 2011-10-29 17:33 +0000
  Re: Another Compiler Error Roedy Green <see_website@mindprod.com.invalid> - 2011-10-29 23:29 -0700

csiph-web