Hello, I would like to know why the form (in java) shows the data in null

1
//Aquí guardo los datos ingresados por teclado
private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {                                             

        if (txtNombre.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Por favor ingrese el nombre");
            return;
        }
        if (txtApellidos.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Por favor ingrese los apellidos");
            return;
        }
        if (txtRut.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Por favor ingrese el RUT");
            return;
        }
        if (txtValidador.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Por favor ingrese el código validador");
            return;
        }
        if (txtEmail.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Por favor ingrese el email");
            return;
        }
        if (txtTelefono.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Por favor ingrese el teléfono");
            return;
        }

        String Nombre, Apellidos, Rut, Email, Telefono;

        Nombre = txtNombre.getText();
        Apellidos = txtApellidos.getText();
        Rut = txtRut.getText();
        Email = txtEmail.getText();
        Telefono = txtTelefono.getText();

        Persona persona = new Persona(Nombre, Apellidos, Rut, Email, Telefono);
        agenda.GuardarPersona(persona);

//Se guardan en esta agenda
public class Agenda {

    Vector vector = new Vector();
    Persona persona = new Persona();

    public void GuardarPersona(Persona persona) {

        if (vector.add(persona)) {
            JOptionPane.showMessageDialog(null, "Se ha agregado correctamente la persona");
        }
    }

//Y finalmente llamo a este metodo pero los datos me salen en null

    public String MostrarAgenda() {
        String Linea = "", Linea2;

        for (int x = 0; x < vector.size(); x++) {
            persona = (Persona) vector.get(x);
            Linea2 =" Nombre: "+ persona.Nombre + " \n " +"Apellido.: "+ persona.Apellidos + " \n " +"Rut.........: "+ persona.Rut + " \n "+"Telefono: " + persona.Telefono;

            Linea = Linea + Linea2 + "\n";
        }
        return Linea;
    }

}

@Franco Rolando imagine you mean this class

public class Persona {

    public String Nombre;
    public String Apellidos;
    public String Rut;
    public String Telefono;

    public Persona() {

    }

    public Persona(String Nombre, String Apellidos, String Rut, String Email, String Telefono) {
    
asked by Yezer.A 22.10.2018 в 07:01
source

2 answers

1

It is already solved, I had to initialize, I needed to add this:

    nombre=Nombre;
    apellidos=Apellidos;
    rut=Rut;
    telefono=Telefono;

}

Thanks, this is my first question in stack overflow, I do not know how to score, I do not even have a reputation to comment. Greetings

    
answered by 22.10.2018 / 07:19
source
0

I can see that you did the same program with which I currently have problems. How did you solve the error that agenda.GuardarPersona(persona); and JOptionPane.showMessageDialog(null,agenda.MostrarAgenda()); the term agenda does not appear in green ?. I do not know what to add.

In advance, I appreciate your response.

    
answered by 16.11.2018 в 15:44