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


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

Another Compiler Error

Started byNovice <novice@example..com>
First post2011-10-29 17:23 +0000
Last post2011-10-29 23:29 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#9300 — Another Compiler Error

FromNovice <novice@example..com>
Date2011-10-29 17:23 +0000
SubjectAnother Compiler Error
Message-ID<Xns9F8D88D6743B5jpnasty@94.75.214.39>
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

[toc] | [next] | [standalone]


#9303 — Please ignore [was Another Compiler Error]

FromNovice <novice@example..com>
Date2011-10-29 17:33 +0000
SubjectPlease ignore [was Another Compiler Error]
Message-ID<Xns9F8D8AA8525F2jpnasty@94.75.214.39>
In reply to#9300
Novice <novice@example..com> wrote in
news:Xns9F8D88D6743B5jpnasty@94.75.214.39: 


Please ignore this thread. The problem was simply that Eclipse got confused 
for some reason. Rebuilding the project eliminated the problem.
Sorry if I wasted anyone's time.
-- 
Novice

[toc] | [prev] | [next] | [standalone]


#9310

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-10-29 23:29 -0700
Message-ID<kirpa713gtck5ei3idrto2k9k24cpb80k4@4ax.com>
In reply to#9300
On Sat, 29 Oct 2011 17:23:02 +0000 (UTC), Novice <novice@example..com>
wrote, quoted or indirectly quoted someone who said :

>Can an enum make references to another enum? 
Sure, but normally you use an EnumSet to create sets of enums.

See http://mindprod.com/jgloss/enumset.html

http://mindprod.com/jgloss/enum.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It's difficult to be rigorous about whether a machine really knows,
thinks, etc., because we’re hard put to define these things. 
We understand human mental processes only slightly better than
a fish understands swimming. 
~ John McCarthy (born: 1927-09-04 died: 2011-10-23 at age: 84).
Inventor of the term AI (Artificial Intelligence), 
the short-circuit OR operator (|| in Java), 
and LISP (LIst Processing Language) that makes EMACS 
(Extensible MACro System) so addictive.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web