gpt4 book ai didi

java - 当我尝试在类中使用 set() 函数时出错

转载 作者:行者123 更新时间:2023-12-02 09:53:01 26 4
gpt4 key购买 nike

我有一个包含 4 个日历变量的类:

public class Ponto {
Calendar entrada;
Calendar saidaAlmoco;
Calendar entradaTarde;
Calendar saida;

public Ponto(Calendar entrada, Calendar saidaAlmoco, Calendar entradaTarde, Calendar saida) {
this.entrada = entrada;
this.saidaAlmoco = saidaAlmoco;
this.entradaTarde = entradaTarde;
this.saida = saida;
}

public void setEntrada(Calendar entrada) {
this.entrada = entrada;
}

public void setSaidaAlmoco(Calendar saidaAlmoco) {
this.saidaAlmoco = saidaAlmoco;
}

public void setEntradaTarde(Calendar entradaTarde) {
this.entradaTarde = entradaTarde;
}

public void setSaida(Calendar saida) {
this.saida = saida;
}
}

然后,当我尝试通过 set() 函数发送值时,它会给出错误:

Attempt to invoke virtual method 'void pt.eu.metaloapp.Ponto.setEntrada(java.util.Calendar)' on a null object reference;

这是代码:

Calendat picagem = Calendar.getInstance();
String hora = sdf.format(picagem.getTime()) + "h";

switch (verificarPonto()) {
case 1:
txtHoraEntrada.setText(hora);
ponto.setEntrada(picagem);
break;
case 2:
txtHoraSaidaAlmoco.setText(hora);
ponto.setSaidaAlmoco(picagem);
break;
case 3:
txtHoraEntradaTarde.setText(hora);
ponto.setEntradaTarde(picagem);
break;
case 4:
txtHoraSaida.setText(hora);
ponto.setSaida(picagem);
break;
}

将日历值发送到类或其他东西是否有任何问题?

最佳答案

您需要在某处调用 new Ponto(),代码中的 pontonull

关于java - 当我尝试在类中使用 set() 函数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56182813/

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