Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未定义隐式超级构造函数事件()_Java_Inheritance_Constructor - Fatal编程技术网

Java 未定义隐式超级构造函数事件()

Java 未定义隐式超级构造函数事件(),java,inheritance,constructor,Java,Inheritance,Constructor,我正在编写一组与抽象超类相关联的子类。有一个默认构造函数,但当我创建另一个构造函数时,它会给我以下错误: 隐式超级构造函数事件未定义。必须显式调用另一个构造函数 我的代码如下: public class Meeting extends Event { private String location; private String subject; private String notes; private String attendeeName; // Array of attendees

我正在编写一组与抽象超类相关联的子类。有一个默认构造函数,但当我创建另一个构造函数时,它会给我以下错误:

隐式超级构造函数事件未定义。必须显式调用另一个构造函数

我的代码如下:

public class Meeting extends Event {

private String location;
private String subject;
private String notes;
private String attendeeName;

// Array of attendees as string
private String[] listofAttendees = new String[10];

public Meeting(Date dueDate, Date reminderDate, String location,
        String subject, String notes) {
    super(dueDate, reminderDate);
    this.location = location;
    this.subject = subject;
    this.notes = notes;

}

public Meeting(String attendeeName) {   // this is the error constructor 
    this.attendeeName = attendeeName;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getSubject() {
    return subject;
}

public void setSubject(String subject) {
    this.subject = subject;
}

public String getNotes() {
    return notes;
}

public void setNotes(String notes) {
    this.notes = notes;
}

public String[] addAttendee(String name) {
    // adding for loop for adding the list of attendees to the array
    for (int i = 0; i < listofAttendees.length; i++) {
        // array index(i) = name of attendee
        listofAttendees[i] = name;
    }

    return listofAttendees;
}

}

您要扩展的对象Event没有不带参数的构造函数。因此,您需要像在其他构造函数中一样调用super并指定参数。

在构造函数中:

public Meeting(String attendeeName) {
    this.attendeeName = attendeeName;
}

您没有像在其他构造函数中那样显式调用super。因此,Java隐式地试图调用基类上的默认构造函数,即Event。您需要在事件中定义一个默认构造函数,或者需要在此构造函数中向一个已定义的事件构造函数添加一个显式调用。

出于好奇,您在询问此问题之前是否先尝试通过谷歌搜索错误消息?是,但没有得到足够的答案,这就是为什么堆栈溢出网站存在于我标记为重复的链接处。这个答案缺少什么?或者这个答案:这些只是搜索错误消息的前几个结果。还有大量其他非SO资源也准确地解释了如何解决这个问题。希望你在这里学到的不是如何解决这个具体问题,而是如何自己找到问题的答案,而不必来到这里问一个以前已经回答过很多次的问题。好的,谢谢你明白我的意思:还有一件事,如何在此构造函数中添加显式调用?\查看原始帖子中的另一个会议构造函数。第一行是:superdueDate,提醒日期;这是对超级构造函数EventDate dueDate、Date RememberDate的显式调用;是否有一个事件构造函数为AttendeerName接受单个字符串参数?如果是,添加SuperAttendeName;作为给你带来问题的构造函数的第一行。若并没有,那个么您需要在事件中创建一个新的构造函数,或者您需要通过super调用其他一些现有的事件构造函数。对super的调用必须是构造函数中的第一件事。