I found error at line LN.Totalbayar= Integer.parseInt(txtTotalBayar.setText(sum+""));
Previously I’ve tried converting from string to integer. please help
private void btnProsesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ClassProgramTiket LN = new ClassProgramTiket();
String hrTiket = txtHargaTiket.getText();
String jmlTiket = txtJumlahTiket.getText();
int harga = Integer.valueOf(hrTiket);
int jumlah = Integer.valueOf(jmlTiket);
int sum = harga * jumlah;
LN.Nama=txtNama.getText();
LN.KodeKereta= (String)cbokodeKereta.getSelectedItem();
LN.NamaKereta=(String)jenisKereta.getSelectedItem();
LN.Jurusan= (String)jurusan.getSelectedItem();
LN.JenisTiket= (String)jenisTiket.getSelectedItem();
LN.HargaTiket= Integer.parseInt(txtHargaTiket.getText());
LN.JumlahTiket= Integer.parseInt(txtJumlahTiket.getText());
LN.Totalbayar= Integer.parseInt(txtTotalBayar.setText(sum+"")); <- Error 'void'
type not allowed here
Tiket.addElement(LN);
}
}
//========== class ClassProgramTiket ====
public class ClassProgramTiket {
public String Nama;
public String KodeKereta;
public String NamaKereta;
public String Jurusan;
public String JenisTiket;
public int HargaTiket;
public int JumlahTiket;
public int Totalbayar;
@Override
public String toString(){
return Nama +"-" + KodeKereta +"-" + NamaKereta + "-" + Jurusan +"-" + JenisTiket
+ "-" + HargaTiket+"-" + JumlahTiket + "-" + Totalbayar;
}
}
>Solution :
LN.Totalbayar= Integer.parseInt(txtTotalBayar.setText(sum+""));
The return type of setText is void. Integer.parseInt expects a String. Setters don’t usually return anything. Their purpose is to change a value, not retrieve it.
I’m not sure why you are trying to change txtTotalBayar while also parsing its value, so it is hard for me to say what the right thing to do is, but perhaps you want something like:
txtTotalBayar.setText(sum+"");
LN.Totalbayar= Integer.parseInt(txtTotalBayar.getText());