The following java code gives the following error: Exception in thread "main" java.util.NoSuchElementException: No line found.
boolean running = true;
while (running) {
Scanner sc2 = new Scanner(System.in);
System.out.println("Enter an item to order:");
String name = sc2.nextLine();
System.out.println("Enter the price:");
String price = sc2.nextLine();
System.out.println("Enter the quantity:");
String quantity = sc2.nextLine();
orderItems.add(name);
orderItems.add(price);
orderItems.add(quantity);
orderItems.add(";");
System.out.println("Would you like to add another item?: (y/n)");
if (sc2.nextLine() != "y") {
running = false;
}
}
Any suggestions? I've gotten a similar error before, which was caused by using a new scanner for each input instead of using the same one for each input, but this error seems to be caused by a different issue. Thanks in advance.