我试图使用carable接口以dd-mm-yyyy hh:mm格式比较约会时间(字符串)。而且,它似乎找不到getAppointmentTime方法,它显然在那里
HW3\Appointment.java:13: error: Appointment is not abstract and does not override abstract method compareTo(Appointment) in Comparable
public class Appointment implements Comparable<Appointment>
^
HW3\Appointment.java:189: error: name clash: compareTo(Object) in Appointment and compareTo(Appointment) in Comparable have the same erasure, yet neither overrides the other
public int compareTo(Object obj)
^
HW3\Appointment.java:191: error: cannot find symbol
return getAppointmentTime().compareTo(obj.getAppointmentTime());
^
symbol: method getAppointmentTime()
location: variable obj of type Object
代码:
package HW3;
import java.lang.Comparable;
public class Appointment implements Comparable<Appointment>
{
private String serviceType;
private int patientID;
private String patientName;
private String appointmentTime;
private String doctorName;
private String symptoms;
public Appointment(String serviceType, int patientID, String patientName, String appointmentTime, String doctorName, String symptoms)
{
this.serviceType = serviceType;
this.patientID = patientID;
this.patientName = patientName;
this.appointmentTime = appointmentTime;
this.doctorName = doctorName;
this.symptoms = symptoms;
}
public String getServiceType()
{
return serviceType;
}
public int getPatientID()
{
return patientID;
}
public String getPatientName()
{
return patientName;
}
public String getAppointmentTime()
{
return appointmentTime;
}
public String getDoctorName()
{
return doctorName;
}
public String getSymptoms()
{
return symptoms;
}
public int compareTo(Object obj)
{
return getAppointmentTime().compareTo(obj.getAppointmentTime());
}
}
尝试下面的代码:
package HW3;
import java.lang.Comparable;
public class Appointment implements Comparable<Appointment> {
private String serviceType;
private int patientID;
private String patientName;
private String appointmentTime;
private String doctorName;
private String symptoms;
public Appointment(String serviceType, int patientID, String patientName, String appointmentTime, String doctorName, String symptoms) {
this.serviceType = serviceType;
this.patientID = patientID;
this.patientName = patientName;
this.appointmentTime = appointmentTime;
this.doctorName = doctorName;
this.symptoms = symptoms;
}
public String getServiceType() {
return serviceType;
}
public int getPatientID() {
return patientID;
}
public String getPatientName() {
return patientName;
}
public String getAppointmentTime() {
return appointmentTime;
}
public String getDoctorName() {
return doctorName;
}
public String getSymptoms() {
return symptoms;
}
@Override
public int compareTo(Appointment obj) {
return getAppointmentTime().compareTo(obj.getAppointmentTime());
}
}
更改:将compareto
方法的方法参数从Object更改为Apption
如何解决此错误,我不想删除。请任何人在不删除`implements actionlistener的情况下更正此错误。
请帮帮忙。我对编码不是新手,但对Java是新手。我不知道我做错了什么。我正在用一本书学习java,下面的代码是我此刻正在研究的。我去了books网站,下载了这个程序的源代码,它给了我同样的错误信息。谁来帮帮我。我知道有人问我这个问题,但我被困住了,真的需要一些帮助。
大家好,我有这个主课堂 错误:(42,8)错误:Home不是抽象的,并且不会覆盖OnFragmentInteractionListener中的onFragmentInteract(String)抽象方法 我创建了一个导航抽屉,并希望有一个新的片段来显示另一个家庭活动的内容。 Android Studio告诉我做个家。类抽象或实现抽象方法。 里面: 我那样做了,但是什么也没有改变。我不能让home类
它会给我错误信息 ExitButtonHandler不是抽象的,并且不重写ActionListener中的抽象方法actionPerformed(ActionEvent
这里怎么了?请帮忙。