1

I am getting a "cannot be resolved" error when I try to do this:

class Tag{
   public static final int blah = 1231; 
}

enum Things{
    COOL (Tag.blah, "blah"); //error here
}

the compiler complains that it cannot find the Tag class on the line above.

1
  • 4
    Having added an appropriate constructor to Things (to take an int and a string) it compiles fine for me... it's probably something in your environment, and you haven't said anything about that. Commented May 25, 2010 at 15:12

4 Answers 4

3

Visibility is probably the error here. Your class Tag has default visibility, so I guess your enum is not in the same package. Use public class Tag

EDIT:

this compiles from inside a common outer class:

class Tag {
    public static final int blah = 1231;
}

enum Things {
    COOL(Tag.blah, "blah"); // error here

    private Things(final int i, final String s) {
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

The following complete EnumTest.java file compile. I'm not sure what your problem is; there isn't enough information.

public class EnumTest {
    class Boo {
        static final int x = 42;
    }
    enum Things {
        X(Boo.x);
        Things(int x) { }
    }
}

2 Comments

@drozzy: if it's visible, it's fine. There's nothing special about enum and static class variables. Try import static Tag.blah; and see if you can even see Tag from Things.
Sorry mistake on my part... see update. Not sure what to do with the question... can't delete it.
0

Well turns out the error was just stupidity on my part.

I was referring to a member variable, (blah in above example) that did not exist! So it wasn't resolving Tag.blah!

Comments

0

Have you defined the constructor of the COOL enum? You are passing it parameters, but the default constructor does not accept any.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.