NoSuchElementException
<p>The program runs successfully, but once the prompt for the user to re-run the program again at the end using the while loop that encapsulates the entire program it throws a NoSuchElementException and despite reading several threads on this forum I can't understand why. Any help would be much appreciated.</p>

<pre><code>import java.util.Scanner;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;

public class billingStatement {

public static void main(String[] args) {
    String again="y";
    while (again.equalsIgnoreCase("y"))
    {
        //Declare Variables
        String userName="", dateIn="";
        int month=0, date=0, year=0;

        // Billing Statement Header
        System.out.println("Southwest Power and Light");
        System.out.println("Billing Statement");

        //Date, Create Template, Print Result
        Date now = new Date();              
        SimpleDateFormat todaysDate = new SimpleDateFormat("MM/dd/yyyy");
        System.out.println("\n"+"Date: " + todaysDate.format(now));

        //Initialize Scanner
        Scanner scan = new Scanner(System.in);

        boolean validName = false;
        while (validName!= true)
        {
            System.out.print("Please enter your name (Last, First): ");
            try
            {
                userName = scan.nextLine();
                validName = true;
            }
            catch (Exception invalidName)
            {
                int loopCount=0;
                loopCount++;
                System.out.println("Unexpected input type. Please enter a valid name.");
                if (loopCount==2) validName = true;
            }
        }

        // Loop prompt until input's valid
        boolean validDate = false;
        while (!validDate)
        {
            try
            {
                System.out.print("Meter reading date (mm/dd/yyyy): ");
                dateIn = scan.nextLine();               
                SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                sdf.setLenient(false);
                sdf.parse(dateIn);
                validDate = true;
            }
            catch (Exception invalidDate)
            {
                System.out.println("Unexpected input. Please enter a valid date.");
            }
        }

        // Use Delimiter
        Scanner scanDate = new Scanner(dateIn);
        scanDate.useDelimiter("/");
        month = scanDate.nextInt();
        date = scanDate.nextInt();
        year = scanDate.nextInt();
        scanDate.close();

        //Meter Reading User Input
        double powerUsed = 0;
        boolean validDouble = false;
        while (!validDouble)
        {
            try
            {
                Scanner scanD = new Scanner(System.in);
                System.out.print("Electricity used (KW): ");
                powerUsed = scanD.nextDouble();
                validDouble = true;
                scanD.close();
            }
            catch (Exception invalidDouble)
            {
                int loopCount=0;
                loopCount++;
                System.out.println("Unexpected input. Please enter a valid number.");
                if (loopCount==2) validDouble = true;
            }
        }

        //Calculate base rate via Meter Read Date
        double baseRate = 0;
        switch (month)
        {
            case 1: //January
                baseRate=0.10;break;
            case 2: //February
                baseRate=0.10;break;
            case 3: //March
                baseRate=0.12;break;
            case 4: //April
                baseRate=0.12;break;
            case 5: //May
                baseRate=0.12;break;
            case 6: //June
                baseRate=0.15;break;
            case 7: //July
                baseRate=0.15;break;
            case 8: //August
                baseRate=0.15;break;
            case 9: //September
                baseRate=0.15;break;
            case 10: //October
                baseRate=0.15;break;
            case 11: //November
                baseRate=0.15;break;
            case 12: //December
                baseRate=0.10;break;
        }

        //Currency Format
        NumberFormat currency = NumberFormat.getCurrencyInstance();

        double totalCharge = 0;
        double baseLineCharge = 0;
        double baseCharge = (baseRate*powerUsed);           
        if(powerUsed&lt;350)
        {
            baseLineCharge = powerUsed*baseRate;
        }
        if(powerUsed&gt;350)
        {
            baseLineCharge = 350*baseRate;
        }       
        //Calculate Total Monthly Charge for Power&gt;350 KW
        if (powerUsed&lt;350)
        {
            totalCharge = baseCharge;
        }
        //Calculate Total Monthly Charge for 500 KW&gt;Power&gt;350 KW
        if (powerUsed&gt;350 &amp; powerUsed&lt;500)
        {
            totalCharge = ((baseRate*350)+((powerUsed-350)*(baseRate*1.10)));
        }
        //Calculate Total Monthly Charge for Power&gt;500 KW
        if (powerUsed&gt;500)
        {
            double pieceChargeOne = (baseRate*350);
            //System.out.println(currency.format(pieceChargeOne));
            double pieceChargeTwo = ((150)*(baseRate*1.10));
            //System.out.println(currency.format(pieceChargeTwo));
            double pieceChargeThree = ((powerUsed-500)*(baseRate*1.25));
            //System.out.println(currency.format(pieceChargeThree));
            totalCharge = pieceChargeOne+pieceChargeTwo+pieceChargeThree;               
        }               

        //Print Output
        System.out.println("\nName: "+ userName);
        System.out.println("Meter Reading Date: " + month + "/" + date + "/" + year);
        System.out.println("Electricity Used (KW): "+ powerUsed);

        System.out.println("Baseline Charge: "+ currency.format(baseLineCharge));
        //System.out.println("Over base Charge: "+currency.format(((powerUsed-350)*(baseRate*1.10))));
        System.out.println("Total Amount Due: "+ currency.format(totalCharge));

        // Prompt user for calculating another bill
        Scanner scanAgain = new Scanner(System.in);
        System.out.print("Calculate another bill (y/n)? ");
        again = scanAgain.nextLine();

        scanAgain.close();
        scan.close();
    }
}   
</code></pre>

<p>}</p>

<p>This is the block that creates the NoSuchElementException. The scanAgain scanner won't read in the System.out.print line above it. Sad day.</p>

<pre><code>        // Prompt user for calculating another bill
        Scanner scanAgain = new Scanner(System.in);
        System.out.print("Calculate another bill (y/n)? ");
        again = scanAgain.nextLine();

        scanAgain.close();
        scan.close();
    }
}   
</code></pre>

<p>}</p>

<p>the exception</p>

<pre><code>Exception in thread "main" java.util.NoSuchElementException:
No line found at java.util.Scanner.nextLine(Unknown Source) at 
billingStatement.main(billingStatement.java:173) –
</code></pre>
