NoSuchElementException, when method is called after code above it is run : <p>When I run my code, it will run fine up to the line "scanner.close()".
After than, when I run the "SumTenNumbers()" method... it will run the first line of the while loop once and crash with the "NoSuchElementException"...
When I remove the code above the line calling the method, it runs fine...
Why does this occur, and how can I solve it?</p>

<p>This is the code:</p>

<pre><code>public class Main
{

    public static void main(String[] args)
    {
        // we use the class "scanner" for input data
        Scanner scanner = new Scanner(System.in); //System.in allows you to type input data into the console which can be returned into the console
        System.out.println("Enter your name: ");
        String name = scanner.nextLine();
        System.out.println("Your name is " + name);

        System.out.println("Enter your year of birth: ");
        boolean isInt = scanner.hasNextInt();
        if (isInt)
        {
            int yearOfBirth = scanner.nextInt();

            int age = 2019 - yearOfBirth;
            if (age &gt;= 0 &amp;&amp; age &lt;= 120)
            {
                System.out.println("You are " + age + " years old");
            }
            else
            {
                System.out.println("Invalid year of birth");
            }
        }
        else
        {
            System.out.println("Unable to parse year of birth");
        }
        scanner.close(); // we must close scanner


        SumTenNumbers();



    }

    public static void SumTenNumbers()
    {
        var reader = new Scanner(System.in);

        int sum = 0;
        int count = 1;

        while (count &lt; 11)
        {
            System.out.println("Enter number " + count + ": ");
            boolean valid = reader.hasNextInt();
            if (valid)
            {
                int userNum = reader.nextInt();
                sum += userNum;
                count++;
            }
            else
            {
                reader.next();
                System.out.println("INVALID");
            }
        }

        System.out.println(sum);

        reader.close();
    }
}
</code></pre>

<p>This is how it looks when I run the code...</p>

<pre><code>Enter your name: 
Siddharth
Your name is Siddharth
Enter your year of birth: 
2001
You are 18 years old
Enter number 1: 
Exception in thread "main" java.util.NoSuchElementException
    at java.base/java.util.Scanner.throwFor(Scanner.java:937)
    at java.base/java.util.Scanner.next(Scanner.java:1478)
    at com.company.Main.SumTenNumbers(Main.java:64)
    at com.company.Main.main(Main.java:39)

Process finished with exit code 1
</code></pre>
