'class'或'interface'预期错误

时间:2017-04-07 12:25:27

标签: java android android-studio

我收到classinterface预期错误。有人知道该如何去做吗?我是java的新手并且正在努力学习!提前致谢。

public class RallyDevice {
    private int _sno;
    private Time _currentTime;
    private double _dist;
    private double _avgSpeed;
    private double _requiredTime;
    private Time _idealTime;
      }

    public RallyDevice(){}

    public RallyDevice(int sno, Time currentTime, double dist,double avgspeed,double requiredtime,Time idealtime) {
        this._sno = sno;
        this._currentTime = currentTime;
        this._dist = dist;
        this._avgSpeed = avgspeed;
        this._requiredTime = requiredtime;
        this._idealTime = idealtime;
    }

    public RallyDevice( Time currentTime, double dist,double avgspeed,double requiredtime,Time idealtime) {
        this._currentTime = currentTime;
        this._dist = dist;
        this._avgSpeed = avgspeed;
        this._requiredTime = requiredtime;
        this._idealTime = idealtime;
    }

1 个答案:

答案 0 :(得分:1)

您必须使用重载的构造函数将您的类封闭在内部,而不是在

之外
public class RallyDevice 
{
    private int _sno;
    private Time _currentTime;
    private double _dist;
    private double _avgSpeed;
    private double _requiredTime;
    private Time _idealTime;
    public RallyDevice()
    {
    }

    public RallyDevice(int sno, Time currentTime, double dist,double avgspeed,double requiredtime,Time idealtime) 
    {
        this._sno = sno;
        this._currentTime = currentTime;
        this._dist = dist;
        this._avgSpeed = avgspeed;
        this._requiredTime = requiredtime;
        this._idealTime = idealtime;
    }

    public RallyDevice( Time currentTime, double dist,double avgspeed,double requiredtime,Time idealtime) 
    {
        this._currentTime = currentTime;
        this._dist = dist;
        this._avgSpeed = avgspeed;
        this._requiredTime = requiredtime;
        this._idealTime = idealtime;
    }
}