I'm trying to make a Java program where the contents of a CSV file of TV show data is stored in an array of TVShow objects. I made the TVShow class have a variable for each of the CSV file's categories.
When I try running, I keep getting a NoSuchElementException. I tried printing out the contents of the file and it worked, but I don't know what is wrong with the program.
Edit: After following advice of @gthanop, I changed the Main.java code below. The issue now is that all of the array's elements are the first row of the CSV file.
This is the CSV file, and then my code:

public class TVShow
{
String name;
String yearPremiered;
String numOfSeasons;
String numOfEpisodes;
String network;
String genre;
String maleLead;
String femaleLead;
public TVShow(String name, String yearPremiered, String numOfSeasons, String numOfEpisodes, String network, String genre, String maleLead, String femaleLead)
{
this.name = name;
this.yearPremiered = yearPremiered;
this.numOfSeasons = numOfSeasons;
this.numOfEpisodes = numOfEpisodes;
this.network = network;
this.genre = genre;
this.maleLead = maleLead;
this.femaleLead = femaleLead;
}
}
import java.io.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws Exception
{
TVShow[] array = new TVShow[20]; //There are 20 rows of TV show data in the CSV file
Scanner read = new Scanner(new File("tv_shows.csv"));
read.nextLine();
int row = 0;
read.useDelimiter(",|\n");
while (read.hasNext())
{
String name = read.next();
String yearPremiered = read.next();
String numOfSeasons = read.next();
String numOfEpisodes = read.next();
String network = read.next();
String genre = read.next();
String maleLead = read.next();
String femaleLead = read.next();
while (row < 20)
{
array[row] = new TVShow(name, yearPremiered, numOfSeasons, numOfEpisodes, network, genre, maleLead, femaleLead);
row++;
}
}
read.close();
for (int i = 0; i < 20; i++)
{
System.out.println(array[i]);
}
}
}