[英]The method xy(double, …) is undefined for the type new ActionListener(){}
I am trying to save my data with this method in file podaci.java: 我正在尝试使用此方法将数据保存在文件podaci.java中:
public Podaci(double brojKalorijaId, int dan, int mjesec, int godina, int proteini,
int ugljikohidrati, int masti, int godine, int masa, int aktivnost, int hr) {
this.brojKalorijaId = brojKalorijaId;
this.dan = dan;
this.mjesec = mjesec;
this.godina = godina;
this.proteini = proteini;
this.ugljikohidrati = ugljikohidrati;
this.masti = masti;
this.godine = godine;
this.masa = masa;
this.aktivnost = aktivnost;
this.hr = hr;
}
I called method in other .java file like this: 我在其他.java文件中这样调用method:
double brojKalorija = (double) (ugljikohidratiInt * 4
+ proteiniInt * 4 + mastiInt * 4)
- (((-20.4022 + (0.4472 * hrInt)
- (0.1263 * masaInt) + (0.074 * godineInt)) / 4.184) * aktivnostInt);
brojKalorija = round(brojKalorija, 2,
BigDecimal.ROUND_HALF_UP);
poruka = "U suficitu ste ~ " + brojKalorija
+ " kalorija.";
JOptionPane.showMessageDialog(null, poruka);
/*here is error*/ Podaci noviPodaci = new Podaci(brojKalorija, danInt,
mjesecInt, godinaInt, proteiniInt,
ugljikohidratiInt, mastiInt, godineInt,
masaInt, aktivnostInt, hrInt);
DatabaseUtils.spremiPodatke(noviPodaci);
The error says: 错误提示:
The method Podaci(double, int, int, int, int, int, int, int, int, int, int) is undefined for the type new ActionListener(){}
Why would I be getting this error? 为什么会出现此错误?
EDIT: podaci.java code is here, I tried to change double to BigDecimal, didn't work 编辑:podaci.java代码在这里,我试图将double更改为BigDecimal,但没有用
package podaci;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "podaci.podaci_izracuna")
public class Podaci {
@Id
@Column(name = "brojKalorija_ID")
@GeneratedValue
private double brojKalorijaId;
@Column(name = "dan")
private int dan;
@Column(name = "mjesec")
private int mjesec;
@Column(name = "godina")
private int godina;
@Column(name = "proteini")
private int proteini;
@Column(name = "ugljikohidrati")
private int ugljikohidrati;
@Column(name = "masti")
private int masti;
@Column(name = "godine")
private int godine;
@Column(name = "masa")
private int masa;
@Column(name = "aktivnost")
private int aktivnost;
@Column(name = "heartRate")
private int hr;
public Podaci(double brojKalorijaId, int dan, int mjesec, int godina, int proteini,
int ugljikohidrati, int masti, int godine, int masa, int aktivnost, int hr) {
this.brojKalorijaId = brojKalorijaId;
this.dan = dan;
this.mjesec = mjesec;
this.godina = godina;
this.proteini = proteini;
this.ugljikohidrati = ugljikohidrati;
this.masti = masti;
this.godine = godine;
this.masa = masa;
this.aktivnost = aktivnost;
this.hr = hr;
}
public Podaci() {}
public double getBrojKalorijaId() {
return brojKalorijaId;
}
public int getDan() {
return dan;
}
public int getMjesec() {
return mjesec;
}
public int getGodina() {
return godina;
}
public int getProteini() {
return proteini;
}
public int getUgljikohidrati() {
return ugljikohidrati;
}
public int getMasti() {
return masti;
}
public int getGodine() {
return godine;
}
public int getMasa() {
return masa;
}
public int getAktivnost() {
return aktivnost;
}
public int getHr() {
return hr;
}
} }
The line 线
Podaci noviPodaci = new Podaci(...);
cannot give an error message saying that it cannot find a method called 'Pocaci' . 无法给出错误消息,指出无法找到名为'Pocaci'的方法 。 The Java compiler should know that
new Podaci(...)
is referring to a constructor not a method. Java编译器应该知道
new Podaci(...)
引用的是构造函数而不是方法。
The only explanations I can think of are: 我能想到的唯一解释是:
Some earlier syntax error in the file where the error message occurs is getting the compiler thoroughly confused. 出现错误消息的文件中的某些较早的语法错误使编译器完全混乱。 Remedy: fix the earlier errors!!
补救措施:修复先前的错误!
Your IDE is confused. 您的IDE感到困惑。 Remedy: try restarting your IDE and "refreshing", and recompiling all of the relevant files.
补救措施:尝试重新启动IDE并“刷新”,然后重新编译所有相关文件。
The code you are compiling is different to the code you are seeing ... and showing us. 您正在编译的代码与您看到的代码以及向我们展示的代码不同。
You have transcribed the error message incorrectly. 您错误地记录了错误消息。
It seems like the problem would be in the definition of one of your variables that you pass to the method. 似乎问题出在传递给方法的变量之一的定义中。 Check or post where you initialize each of them... make sure they are all INT.
检查或发布初始化它们的位置...确保它们都是INT。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.