I thought having println() at the end is adding an extra empty line and that is the problem but even after adding a condition (If condition) such that there are exactly 2 rows and no extra empty rows, still I see the same error