gpt4 book ai didi

java - 与默认构造函数作斗争,隐式 super 构造函数未定义

转载 作者:行者123 更新时间:2023-12-02 06:45:30 25 4
gpt4 key购买 nike

我有两个类(class),一门称为“俱乐部”,一门称为“约会”。 - 日期延长俱乐部

当我在下面添加这段代码时:在 Clubs 类中,它会弄乱我的 Date 类以及所有扩展 Clubs 的其他类。

public Clubs(Parcel in) { readFromParcel(in); }

这是我的约会类(class)

public class Date extends Clubs {
public Date(String day){
clubName = day;
date = "";
eventType = "";
}
}

implicit super constructor Clubs() is undefined must explicitly invoke another constructor

上面的消息是当我将鼠标悬停在 public Date(String day){ 上的红色下划线时收到的错误

任何帮助将不胜感激:

下面我发布了俱乐部类(class)

public class Clubs implements Parcelable{   
protected String clubName;
protected String address;
protected String postcode;
protected String contactName;
protected String contactPhone;
String date, eventType, scrutTime, startTime, eventName, week;


public Clubs(String e){

}

public String getDetails() {
return address + " " + postcode + " " + contactName + " " + contactPhone + " " + date + " " + eventType + " " + scrutTime + " ";
}

public String getEvent() {
return date + " " + eventType;
}

public String getName(){
return clubName;
}

public String getDate(){
return date;
}

public String getWeek(){
return week;
}

public String geteventName(){
return eventName;
}

public void setEvent(String eventType, String date, String scrutTime, String startTime, String eventName, String week) {
this.eventType = eventType;
this.date = date;
this.scrutTime = scrutTime;
this.startTime = startTime;
this.eventName = eventName;
this.week = week;
}

public void setEvent(String eventType, String date) {
this.eventType = eventType;
this.date = date;
}

最佳答案

当你编写子类时,编译器会自动将对 super 构造函数(父类(super class)的构造函数)的调用插入到子类构造函数的第一行。但是,您的 Clubs 类没有默认构造函数(没有参数的构造函数),并且编译器不知道使用哪个 String 参数来调用存在的构造函数,因此它会提示。

要解决您的问题,您必须在 Date 构造函数中添加以下内容作为第一行:

super("some string that makes sense in your case");

关于java - 与默认构造函数作斗争,隐式 super 构造函数未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18678380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com