The error it presents is:
Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine (Unknown Source).
I have a readAddress method that gets the values of the class. This method is called from another class Employee
to read Address
of Employee
among other attributes. I attach the two methods. When I test the methods separately it works well.
public void readAddress() {
Scanner read = new Scanner(System.in);
String string;
System.out.println("Address(Separate each data with '/'): ");
string = read.nextLine();
String[] substring = string.split("/");
this.building = substring[0];
this.apartment = substring[1];
this.street = substring[2];
this.city = substring[3];
this.province = substring[4];
this.code = substring[5];
read.close();
}
public void readEmployee() {
Scanner read = new Scanner(System.in);
System.out.println("Last name: ");
this.lastname = read.nextLine();
System.out.println("First name: ");
this.firstname = read.nextLine();
this.email.readEmail();
this.address.readAddress();
this.telephone.readTelephone();
System.out.println("Social security number: ");
this.ssn = read.nextLine();
read.close();
}
The error is on the line:
string = read.nextLine();