I would like to fix the java.util.NoSuchElementException bug. I keep getting the error:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at Main.newUser(Main.java:28)
at Main.main(Main.java:18)
with this code
import java.util.Scanner;
import java.io.*;
class Main2
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
input.close();
newUser();
}
private static void newUser()
{
try
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter the name for the new user.");
String userNameNew = input.nextLine();
System.out.println("Please enter the password for the new user.");
String userPassWordNew = input.nextLine();
System.out.println("The new user: " + userNameNew + " has the password: " + userPassWordNew + "." );
PrintWriter out = new PrintWriter("users.txt");
out.print(userNameNew + "\r\n" + userPassWordNew);
out.close();
input.close();
} catch (IOException e) { e.printStackTrace(); }
}
}
Can you please help me? Thank you.