Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.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_Arrays_String - Fatal编程技术网

Java不能应用于给定的字符串和整数类型

Java不能应用于给定的字符串和整数类型,java,arrays,string,Java,Arrays,String,我在编译时遇到了这个错误,我不知道为什么会出现这个错误或者如何修复它 错误是: RecordEvents3.java:16: error: constructor EventInformation in class EventInformation cannot be applied to given types; EventInformation e = new EventInformation("10:53",45); ^ requi

我在编译时遇到了这个错误,我不知道为什么会出现这个错误或者如何修复它

错误是:

RecordEvents3.java:16: error: constructor EventInformation in class EventInformation cannot be applied to given types;
   EventInformation e = new EventInformation("10:53",45);
                        ^
  required: no arguments
  found: String,int
  reason: actual and formal argument lists differ in length
1 error
类记录事件3{
公共静态void main(字符串参数[]){
记录器r1=新记录器(100100,“袋熊检测”);
r1.记录事件(“10:53”);
r1.记录事件(“10:59”);
r1.记录事件(“11:05”);
r1.记录事件(“12:59”);
r1.记录事件(“13:50”);
r1.记录事件(“14:06”);
r1.printEvents();
事件信息e=新的事件信息(“10:53”,45);
System.out.println(“在”+e.eventTime记录的事件+
“,datum=“+e.eventDatum”);
}
}
类事件信息{
公共字符串事件时间;
公共事件数据;
}
课堂记录员{
int XPO,YPO;
字符串事件类型;
字符串[]事件=新字符串[6];
最终int事件_Max=10;
int-xevent=0;
记录器(intxpos、intypos、stringeventtype){
this.xPos=xPos;
this.yPos=yPos;
this.eventType=eventType;
}
void recordEvent(字符串eventTime){
事件[xevent]=事件时间;
xevent++;
如果(xevent>5){
System.out.println(“事件日志溢出-终止”);
系统出口(1);
}
}
void printEvents(){
System.out.println(“记录”+事件类型+
“在[“+xPos+”、“+yPos+”]发生的事件”;
int指数=0;
用于(字符串当前:事件){
如果(xevent>5){
String ss=String.format(“事件编号%s记录在”,索引);
系统输出打印项次(ss+电流);
索引++;
}
}      
}
}

您的EventInformation类需要一个类似

public EventInformation(String eventTime, int eventDatum) {
   this.eventTime = eventTime;
   this.eventDatum = eventDatum;
}

看起来您希望Java构造函数的行为类似于Typescript构造函数。初始化字段时始终需要显式构造函数。

需要使用相应的参数指定构造函数。
如果类中没有指定构造函数,则将创建不带参数的默认构造函数,并使用
null

初始化字段引用。您没有为类
事件信息创建带参数的构造函数,但您正在代码中使用带参数的构造函数,这是您的构造函数

class EventInformation {
    public String eventTime;
    public int eventDatum;
}
改用

class EventInformation {
    public String eventTime;
    public int eventDatum;

    EventInformation(String eventTime, int eventDatum) {
        this.eventTime=eventTime;
        this.eventDatum=eventDatum;
    }
}

是的,您没有像
neweventinformation(“10:53”,45)这样的构造函数不能调用不存在的构造函数。代码中没有EventInformation(String,int),因此如果编译器接收到这两个输入,它将完全不知道如何处理它们。默认构造函数为空,不初始化任何字段。