Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6040537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:31:41+00:00 2026-05-23T06:31:41+00:00

Huzzah! This code worked for a time, then I decided to add a default

  • 0

Huzzah!

This code worked for a time, then I decided to add a default color, and it stopped working. I get the following error:

1 error found:
File: Status.java  [line: 20]
Error: Status.java:20: illegal reference to static field from initializer

With the following code at compile-time.

import java.awt.Color;

enum Status
{
  OFF ("Off"),
  TRAINING ("Training", new Color(255, 191, 128)),
  BEGINNER ("Beginner", new Color(128, 255, 138)),
  INTERMEDIATE ("Intermediate", new Color(128, 212, 255)),
  ADVANCED ("Advanced", new Color(255, 128, 128));

  public final String name;
  public final Color color;

  public static final Color defaultColor = Color.WHITE;

  Status(String name)
  {
    this(name, defaultColor);
  }
  Status(String name, Color color)
  {
    this.name = name;
    this.color = color;
  }
}

This should work, as far as I can tell, but for whatever reason Java decided to throw an error.
Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:31:42+00:00Added an answer on May 23, 2026 at 6:31 am

    defaultColor will only be initialized after the constructors have been called – so it will have its default value (null) until that time. One option would be to put the default colour in a nested type:

    import java.awt.Color;
    
    enum Status
    {
      OFF ("Off"),
      TRAINING ("Training", new Color(255, 191, 128)),
      BEGINNER ("Beginner", new Color(128, 255, 138)),
      INTERMEDIATE ("Intermediate", new Color(128, 212, 255)),
      ADVANCED ("Advanced", new Color(255, 128, 128));
    
      public final String name;
      public final Color color;
    
      Status(String name)
      {
        this(name, Defaults.COLOR);
      }
      Status(String name, Color color)
      {
        this.name = name;
        this.color = color;
      }
    
      private static class Defaults
      {
         private static Color COLOR = Color.WHITE;
      }
    }
    

    Of course, if you’re only referring to the default colour once in the code, you might as well hard-code it within the constructor call:

    Status(String name)
    {
      this(name, Color.WHITE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've discovered that any time I do the following: echo '<a href=http:// title=bla>huzzah</a>'; I
Greetings! I have a working iPhone app (huzzah!) that uses a MainView.xib containing a
XMLNotepad provides the following text (for example) when a transform fails: Error Transforming XML
I'm working on a SmartGWT project where I'd like my main navigation to be
I think I've worked myself into a pretty stupid corner, here. Let me show
I'm wondering about this: I have a simple facebook-connect app that will only show
I tried to follow the directions on autonumbering cells in a Mathematica-8 notebook, here
I have a situation where say, a Notebook stores Pages . At first, I
I don't have a lot of experience with PHP - I used a form
I'm creating an app using the andengine for Android. I'm autogenerating some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.