I have problem with InvocationTargetException. I am setting values of object using scanner and it became to return such strange exception for me. I did read doc and i was searching internet to find solution, but I can't figure out what's wrong. Also don't read println strings, they are in my native language.
public Person SignPerson() {
Scanner scanner = new Scanner(System.in);
System.out.println("Tworzymy twoje konto użytkownika, podaj dane osobowe");
System.out.println("Podaj swoj pesel");
String id = setPersonalId();
Person person = new Person(id);
System.out.println("Podaj swoje imie");
person.setFirstName(scanner.nextLine()); // the line taht causes problem (other
// scanners also throws exceptions)
System.out.println("Podaj drugie imie");
//tutaj powinien byc wgrany drugi kod do odczytu imienia
System.out.println("Podaj nazwisko");
person.setLastName(scanner.nextLine());
System.out.println("Podaj nazwisko panienskie matki");
person.setMotherMaidensName(scanner.nextLine());
return person;
}
public static String setPersonalId() {
String id;
try (
Scanner scanner2 = new Scanner(System.in);
) {
id = scanner2.next();
char[] chars = id.toCharArray();
for (char aChar : chars) {
if (!(aChar >= '0' && aChar <= '9'))
throw new InvalidStringException();
}
return id;
} catch (InvalidStringException e) {
System.out.println("Wprowadziles niepoprawny pesel");
}
return null;
}