nus-cs2113-AY2021S2 / forum

5 stars 0 forks source link

About text-ui-test #27

Open NgManSing opened 3 years ago

NgManSing commented 3 years ago

I am trying to use the batch file which is for text-ui testing. I have put some inputs into input.txt and have written the expected output into EXPECTED.TXT.

input.txt image

EXPECTED.TXT image

However, the program only takes the first line in the input.txt and ignored other lines. The compiler replied "Exception in thread "main" java.util.NoSuchElementException: No line found". image

Where have I made mistakes?

8kdesign commented 3 years ago

For expected.txt, you only want to include the parts that the program outputs and exclude what the user is supposed to input.

kewenlok commented 3 years ago

I believe the NoSuchElementException error can be solved by checking if your scanner object has next line using hasNextLine() method before getting the nextLine() value or in the while loop.

NgManSing commented 3 years ago

I find out that if I declare the Scanner object outside a static method (i.e. declare the static final Scanner object globally) can solve the problem.