Skip to content
Advertisement

Tag: nosuchelementexception

Why am I getting “NoSuchElementException” When I can print everything from textfile?

I’m able to read everything from the text file and print the data yet I get a “No Such Element” Exception. All the solutions i’ve found say to use “HasNext” in while loop and yet it doesn’t seem to work for me public void fileReader() throws IOException { C001,Toyota,Yaris,Sedan,2012,4,Blue,50,15,10,10 C002,Toyota,Corolla,Hatch,2020,4,White,45,20,10,10 C003,Toyota,Kluger,SUV,2019,7,Grey,70,20,20,10 C004,Audi,A3,Sedan,2015,5,Red,65,10,20,10 C005,Holden,Cruze,Hatch,2020,4,Green,70,10,10,10 C006,BMW,X5,SUV,2018,7,White,100,25,20,10 C007,BMW,320i,Sedan,2021,5,Grey,75,10,15,N/A C008,Ford,Focus,Sedan,2014,5,Red,45,10,10,N/A C009,Ford,Puma,SUV,2015,5,Black,70,20,15,20 This is the

java.util.NoSuchElementException – Scanner reading user input

I’m new to using Java, but I have some previous experience with C#. The issue I’m having comes with reading user input from console. I’m running into the “java.util.NoSuchElementException” error with this portion of code: I have two functions that get user input: PromptCustomerQty PromptCustomerPayment If I don’t call PromptCustomerQty then I don’t get this error, which leads me to

Advertisement