1

I have defined an enum. When I try to write:

private ENUM_NAME variableName;

as the instance variable of a class, the compiler tells me:

cannot find symbol - class ENUM_NAME

which is preventing me from continuing.

I am using the BlueJ IDE, if that matters. All files are contained within one package, and are in the same folder on my computer. I began with the enum inside of another class (a test driver for my working class), and I got the stated error in my working class. Then I tried making the enum its very own class, and I got the same error.

The test driver class:

public class BicycleMainClass
{
    enum BICYCLE_TYPE_ENUM {STANDARD, RACER, MOUNTAIN, BMX};
    //main method below
}

The "working" class:

public class BicycleClass
{
    private BICYCLE_TYPE_ENUM bicycleType;
    //this line gives me the error "cannot find symbol - class BICYCLE_TYPE_ENUM"
}

I would expect it to compile without error, because enums are a valid variable type. What am I not understanding?

Alex B
  • 13
  • 1
  • 4

3 Answers3

2

The problem is that you have declared your enum type as a nested type of BicycleMainClass, so you need to include the outer type when referring to it:

class BicycleClass
{
    private BicycleMainClass.BICYCLE_TYPE_ENUM bicycleType;
}

Another solution is simply to declare your enum type as a top-level type:

public enum BICYCLE_TYPE_ENUM {
    STANDARD, RACER, MOUNTAIN, BMX;
}

Then you can refer to it directly:

private BICYCLE_TYPE_ENUM bicycleType;
SDJ
  • 4,083
  • 1
  • 17
  • 35
0

You need to add import statement for BICYCLE_TYPE_ENUM. Please make sure you use proper package name while adding the import statement.

0

Please try with static import for nested enums

or

try this private BicycleMainClass.BICYCLE_TYPE_ENUM bicycleType;

Hope this will help..