I have the following Classes:
public class Human {
private String firstName;
private String lastName;
public Human(){
Scanner in = new Scanner(System.in);
System.out.println("Please enter Firstname");
setFirstName(in.nextLine());
System.out.println("Please enter Lastname");
setLastName(in.nextLine());
in.close();
}
}
And
public class Customer extends Human{
private long customerNumber;
private String customerCompanyName;
static long customerNumberCounter = 0;
public Customer(){
super();
Scanner in = new Scanner(System.in);
setCustomerNumber(customerNumberCounter);
customerNumberCounter ++;
System.out.println("Please enter Companyname");
setCustomerCompanyName(in.nextLine());
in.close();
}
}
When i call the following Main Method:
public static void main(String[] args) {
Customer aCustomer = new Customer();
System.out.println(aCustomer.giveFullName());
}
The Programm throwes the following Error:
Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at customers.Customer.(Customer.java:17) at customers.Customer.main(Customer.java:22)
I don't understand what I am doing wrong, since I can create an Object of Class Human without any problems but when I create a Customer, the Error pops up directly after entering the LastName in the Human Constructor.
I already renamed the Scanner and so on but that didn't solve the problem.
Anybody got a Solution for this?