0

When I use this class it shows some errors.

Class:

public static final class ScreenOrientation extends Enum
    {

        private static final ScreenOrientation ENUM$VALUES[];
        public static final ScreenOrientation LANDSCAPE_FIXED;
        public static final ScreenOrientation LANDSCAPE_SENSOR;
        public static final ScreenOrientation PORTRAIT_FIXED;
        public static final ScreenOrientation PORTRAIT_SENSOR;

        public static ScreenOrientation valueOf(String s)
        {
            return (ScreenOrientation)Enum.valueOf(org/andengine/engine/options/EngineOptions$ScreenOrientation, s);
        }

        public static ScreenOrientation[] values()
        {
            ScreenOrientation ascreenorientation[] = ENUM$VALUES;
            int i = ascreenorientation.length;
            ScreenOrientation ascreenorientation1[] = new ScreenOrientation[i];
            System.arraycopy(ascreenorientation, 0, ascreenorientation1, 0, i);
            return ascreenorientation1;
        }

        static 
        {
            LANDSCAPE_FIXED = new ScreenOrientation("LANDSCAPE_FIXED", 0);
            LANDSCAPE_SENSOR = new ScreenOrientation("LANDSCAPE_SENSOR", 1);
            PORTRAIT_FIXED = new ScreenOrientation("PORTRAIT_FIXED", 2);
            PORTRAIT_SENSOR = new ScreenOrientation("PORTRAIT_SENSOR", 3);
            ScreenOrientation ascreenorientation[] = new ScreenOrientation[4];
            ascreenorientation[0] = LANDSCAPE_FIXED;
            ascreenorientation[1] = LANDSCAPE_SENSOR;
            ascreenorientation[2] = PORTRAIT_FIXED;
            ascreenorientation[3] = PORTRAIT_SENSOR;
            ENUM$VALUES = ascreenorientation;
        }

        private ScreenOrientation(String s, int i)
        {
            super(s, i);
        }
    }

When extending Enum it shows The type q may not subclass Enum explicitly error.

How can I create an enum using these fields?
How can I modify this class to use like Enum?

rgettman
  • 176,041
  • 30
  • 275
  • 357
Randolph
  • 951
  • 2
  • 11
  • 24

1 Answers1

4
public enum ScreenOrientation {

    LANDSCAPE_FIXED("LANDSCAPE_FIXED", 0);
    // other values

    private final String s;
    private final int i;

    private ScreenOrientation(String s, int i) {
        this.s = s;
        this.i = i;
    }

    // getters for s and i

    @Override
    public String toString() { 
        return this.getS();
    }

    public static ScreenOrientation fromS(String s) {
        for( ScreenOrientation so : values())
            if(so.getS().equalsIgnoreCase(s)) {
                return so;
        }
       throw new IllegalArgumentException();
    }
}

Not sure what s and i equate to so give them more meaningful names. Also, override toString method as suggested in Javadocs:

http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#name()

JamesB
  • 7,774
  • 2
  • 22
  • 21
  • 's' is redundant, and everything that goes with it. Enum items already have their own name as toString() values. – user207421 May 27 '14 at 22:07
  • 1
    @EJP How do you know s is the same as name? The OP has given no further info on what s is. – JamesB May 27 '14 at 22:14