I am getting this error: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

I wrote codes to locate specific elements within a region. I changed code to a method to call it easier. The code works on its own but when i use the method it gives me error!

@Test public void purchaseACourseTest() {

    driver.get("https://www.thegreatcourses.com/");
    selectACourseCatagory("Science");
}
    private void selectACourseCatagory(String courseCatagoryName) {
    WebElement parentElem = driver.findElement(By.cssSelector(".itemslider-wrapper.itemslider-categories"));
    List <WebElement> catagoryCourse = parentElem.findElements(By.tagName("li"));

    for (WebElement li : catagoryCourse) {
        List<WebElement> imgElem = li.findElements(By.tagName("img"));
        String altText = imgElem.get(0).getAttribute("alt");
        System.out.println("The text is: " + altText);
        if(altText.contains("courseCatagoryName")) {
            imgElem.get(0).click();
            break;
        }
    }
}

The method is supposed to click on the name of the course which i pass, but instead i get this error: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0