Java Enum默认显式构造函数未定义

时间:2013-07-18 01:51:47

标签: java enums

我向你保证这将是一个非常愚蠢的问题,但我有一个脑块,无法弄清楚如何解决这个错误。我正在使用Java并尝试定义一个Enum。

public enum ShooterStatus{ OFF,EXTENDING,CONTRACTING,LOADED }

此枚举在另一个类中定义。编译时,我收到以下错误:

Implicit super constructor Enum(String, int) is undefined for default constructor. Must define an explicit constructor

我在这里缺少什么?枚举声明不应该是这样的吗? (我习惯用C编程)

包含类:

package org.usfirst.frc3777;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Timer;

public class Shooter {

    public enum ShooterStatus{
        OFF,EXTENDED,CONTRACTING,LOADED
    }

    SpeedController upperCont;
    SpeedController lowerCont;
    DoubleSolenoid dS;

    Boolean isLoaded;
    Boolean isRunning;

    Timer mainTimer;

    DoubleSolenoid.Value extend = DoubleSolenoid.Value.kForward;
    DoubleSolenoid.Value compress = DoubleSolenoid.Value.kReverse;
    DoubleSolenoid.Value off = DoubleSolenoid.Value.kOff;

    String label = "Shooter";

    private boolean wheelsRunning(){
        return upperCont.get()>.5&&lowerCont.get()>.5;
    }

    public Shooter(SpeedController upperCont, SpeedController lowerCont, DoubleSolenoid dS){
        this.upperCont = upperCont;
        this.lowerCont = lowerCont;
        this.dS = dS;
    }

    private void setExtendPiston(){
        dS.set(extend);
    }

    private void setCompressPiston(){
        dS.set(compress);
    }

    private void setOffPiston(){
        dS.set(off);
    }

    public boolean startShootingThread(){
        if(!isLoaded){
            Log.info(label, "Shooter is not currently loaded in logic");
            return false;
        }
        if(isRunning){
            Log.info(label, "Shooter is currently running");
            return false;
        }
        setExtendPiston();
    }
}

1 个答案:

答案 0 :(得分:-2)

摆脱分号。从这里开始:

public enum ShooterStatus{ OFF,EXTENDING,CONTRACTING,LOADED; }

到此:

public enum ShooterStatus{ OFF,EXTENDING,CONTRACTING,LOADED }

更多信息here

您还应该检查是否定义了默认的JDK。