Very good, I could be given a hand with this error, I need to be able to parse the input (whole) from the keyboard and pass it to an object
/**Clase Main: **/
public class app {
public static void main(String[] args) {
Persona per =new Persona();
Fecha fecha =new Fecha();
PersonaConNacimiento persona = new PersonaConNacimiento();
persona.inputPersonaConNacimiento(per,fecha);
//persona.showPersonaConNacimiento();
}
}
Class PersonaConNacimiento
:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PersonaConNacimiento extends Persona {
Fecha nacimiento;
public PersonaConNacimiento() {
super();
}
public void inputPersonaConNacimiento(Persona persona, Fecha fecha) {
BufferedReader dato = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingrese Nombre");
try {
this.setNombre(dato.readLine());
} catch (IOException e) {
System.out.println(e.getMessage());
}
System.out.println("Ingrese Apellido");
try {
this.setApellido(dato.readLine());
} catch (IOException e) {
System.out.println(e.getMessage());
}
System.out.println("Ingrese dni");
try {
this.setDni(Integer.parseInt(dato.readLine()));
} catch (IOException e) {
System.out.println(e.getMessage());
}
/***************************HELP*****************************************/
System.out.println("Ingrese Fecha- : día, formato dd");
try {
this.nacimiento.setDia(Integer.parseInt(dato.readLine()));
} catch (IOException e) {
System.out.println(e.getMessage());
}
System.out.println("Ingrese mes, formato mm");
try {
this.nacimiento.setMes(((Integer.parseInt(dato.readLine()))));
} catch (IOException e) {
System.out.println(e.getMessage());
}
System.out.println("Ingrese año, formato aaaa");
try {
this.nacimiento.setAnho((Integer.parseInt(dato.readLine())));
} catch (IOException e) {
System.out.println(e.getMessage());
}
/*************************FIN HELP *******************************************/
}
public void showPersonaConNacimiento() {
System.out.println("la fecha es: " + this.nacimiento.getDia() + "/"
+ this.nacimiento.getMes() + "/"
+ this.nacimiento.getAnho());
System.out.println("Nombre: " + this.getNombre() + "\n"
+ " Apellido: " + this.getApellido() + "\n"
+ "Dni: " + this.getDni());
}
@Override
public String toString() {
return "Trabaj práctico 1 enunciado 2";
}
public Fecha getNacimiento() {
return nacimiento;
}
public void setNacimiento(Fecha nacimiento) {
this.nacimiento = nacimiento;
}
}
This is the output with the error.
Ingrese Nombre
name Enter Surname surname Enter ID 2. 3. 4. 5 Enter Date-: day, dd format 2. 3 Exception in thread "main" java.lang.NullPointerException at PersonConNacimiento.inputPersononaConNacimiento (PersonaConNacimiento.java:45) at app.main (app.java:11)