public void crearCliente() {
int i, k, j, l;
registro r = new registro();
k = lr.getSize();
for (i = 0; i < k; i++) {
r = lr.get(i);
l = r.getSize();
String contenido[] = new String[8];
for (j = 0; j < l; j++) {
contenido[j] = r.getCampoR(j);
//System.out.println(contenido[j]);
}
c1 = new Cliente(contenido[0], contenido[1], contenido[2], contenido[3], contenido[4], contenido[5], contenido[6], contenido[7]);
c1.verCliente();}
In this code, at the end,I assign a value to c1, but when I print it i get null in all the c1 fields. I write my code down for the class Cliente. I want to print all the values i gave to c1 but i do not know why it print null in all the fields. I follow the code using the debugger and everything is right until the sentences which assign all the values to the new variable.
public class Cliente {
private String Id_cliente;
private String Cod_postal;
private String Numero;
private String Calle;
private String Provincia;
private String Poblacion;
private String Telefono;
private String Apellidos;
public Cliente(String idc, String cp, String num, String cal, String prov, String pob, String tlf, String aps){
idc = Id_cliente;
cp = Cod_postal;
num = Numero;
cal = Calle;
prov = Provincia;
pob = Poblacion;
tlf = Telefono;
aps = Apellidos;
}
public void verCliente(){
System.out.println("Id_cliente: "+ Id_cliente);
System.out.println("Codigo postal: "+ Cod_postal);
System.out.println("Numero: "+ Numero);
System.out.println("Calle: "+ Calle);
System.out.println("Provincia: "+ Provincia);
System.out.println("Poblacion: "+ Poblacion);
System.out.println("Telefono: "+ Telefono);
System.out.println("Apellidos: "+ Apellidos);
}
}
You should change this
to
You are assigning a values to your method parameters, rather than fields. Same applies to all of the parameters in your constructor
Cliente
.Your constructor for the class Cliente is switching assignement. Change the idc = Id_cliente to Id_cliente = ic.
Your assignments are backwards in your constructor. Switch the left and right hand sides of all those and it should work.