Reputation: 370
I am trying to save my data with this method in file 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:
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
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;
}
}
Upvotes: 1
Views: 2689
Reputation: 9997
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.
Upvotes: 0
Reputation: 719376
The line
Podaci noviPodaci = new Podaci(...);
cannot give an error message saying that it cannot find a method called 'Pocaci'. The Java compiler should know that new Podaci(...)
is referring to a constructor not a method.
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. Remedy: try restarting your IDE and "refreshing", and recompiling all of the relevant files.
The code you are compiling is different to the code you are seeing ... and showing us.
You have transcribed the error message incorrectly.
Upvotes: 1