I have a problem reading data int with 'nextInt' and I do not know what it can be. I leave the method that is giving me the error; If something is missing or you want the complete code, you can ask me. Could you tell me what it can be?
static int numero_DNI;
static ArrayList<Integer> DNI = new ArrayList <Integer>();
static boolean comprobar;
protected ArrayList<Integer> ImportarDNI() {
Scanner sc = new Scanner (System.in);
numero_DNI = sc.nextInt();
DNI.add(numero_DNI);
if (DNI.size() > 7 && DNI.size()<0) {
System.err.println("El DNI debe tener los 7 números");
comprobar = false;
} else {
comprobar = true;
}
sc.close();
return DNI;
}
Errors:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Personas.Persona.ImportarDNI(Persona.java:30)
at Personas.Persona.main(Persona.java:64)